.Net different IL but same output. Why? - asp.net

I have 2 dlls ('original' and 'new') and for one method the IL is very different inside these 2 dlls (not talking about the nop alone but lot of differences). But when I decompile these two dlls then the C# produced is exactly same for these two.
Why it is happening? Is it OK and valid scenario? Can I assume the functionality is same based on decompiled C# code (though the IL are lot different)?
Other Info:
Visual Studio 2008 (3.5).
Method contains long chain of switch...case statements.
I can not modify the 'original' dll (c# code) but I can modify the C# code of 'new' dll to regenerate the dll and compare again.
IL sample is very big otherwise I could have pasted here.
I am unable to find a way to make the IL of 'new' dll (by modifying the C# code) exact same as 'original' dll. Any suggestion to achieve this?

Related

Make T4MVC work with ASP.NET 5

According to the latest comments in this thread, .tt templates will now after all be supported in ASP.NET 5 starting with Visual Studio Update 1.
Which IMHO would be great because after using T4MVC for years, I certainly don't wanna go back to using magic strings for route/view names (error prone and not refactoring-friendly).
However, I can't quite get it to work with ASP.NET 5 RC and Visual Studio Professional 2015 Update 1.
Here's what I've tried:
Adding the T4MVC NuGet (3.16.5) to a blank ASP.NET 5 solution: nope, CoreCLR complains and no .tt files are added to project:
Error NU1002 The dependency T4MVCExtensions 3.16.5 in project
WebApplication1 does not support framework DNXCore,Version=v5.0.
Add the NuGet to a classic ASP.NET 4.6 solution and manually copy over T4MVC.tt, T4MVC.tt.hooks.t4 and T4MVC.tt.settings.xml to the ASP.NET 5 solution: Visual Studio indeed offers to "Run Custom Tool" on the .tt file....
... but running the transformation throws a NullReferenceException:
Severity Code Description Project File Line Suppression State
Error Running transformation: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.VisualStudio.TextTemplating3FE65EE761BB32C4AE5AEEB1949A6FC143551E0A56C74E6B36511A416E2DE40FB92F7CB1BC6FC7A97FF5B622AE39377BBFB9463480555898ADB8DD6D286C533D.GeneratedTextTransformation.GetProjectItem(ProjectItems items, String subPath) in c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt:line 1398
at Microsoft.VisualStudio.TextTemplating3FE65EE761BB32C4AE5AEEB1949A6FC143551E0A56C74E6B36511A416E2DE40FB92F7CB1BC6FC7A97FF5B622AE39377BBFB9463480555898ADB8DD6D286C533D.GeneratedTextTransformation.GetProjectItem(Project project, String name) in c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt:line 1378
at Microsoft.VisualStudio.TextTemplating3FE65EE761BB32C4AE5AEEB1949A6FC143551E0A56C74E6B36511A416E2DE40FB92F7CB1BC6FC7A97FF5B622AE39377BBFB9463480555898ADB8DD6D286C533D.GeneratedTextTransformation.ProcessAreas(Project project) in c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt:line 600
at Microsoft.VisualStudio.TextTemplating3FE65EE761BB32C4AE5AEEB1949A6FC143551E0A56C74E6B36511A416E2DE40FB92F7CB1BC6FC7A97FF5B622AE39377BBFB9463480555898ADB8DD6D286C533D.GeneratedTextTransformation.PrepareDataToRender(TextTransformation tt) in c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt:line 557
at Microsoft.VisualStudio.TextTemplating3FE65EE761BB32C4AE5AEEB1949A6FC143551E0A56C74E6B36511A416E2DE40FB92F7CB1BC6FC7A97FF5B622AE39377BBFB9463480555898ADB8DD6D286C533D.GeneratedTextTransformation.TransformText() in c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt:line 40 WebApplication3 c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt 1398
Any other suggestions?
See also this related question about alternatives to T4MVC in ASP.NET 5.
As David Ebbo (hey!) pointed out, R4MVC - a side project was started a long time ago, but was stalled due to (at the time) breaking changes in the Roslyn compiler.
Luckily, the project was revived, and R4MVC has just released it's first alpha build, with more changes coming soon.
While the project works somewhat differently, and isn't using t4 templates, the end result is the same, and we're working to achieve feature parity with T4MVC in the near future.
At this point, T4MVC is not designed to run on ASP.NET 5 projects, so I'm not surprised that it doesn't work.
A while back, a separate R4MVC project was started, using a Roslyn based approach. However, this was done at a time when there was no T4 support with ASP.NET 5, and that has now been revisited.
So it's possible that there is hope to get T4MVC running on there, but someone would need to invest the time to see how far it is from working.
I just took a tiny step and fixed the null ref that you hit (not yet released, you'll need to hand fix). However, I then hit a condition where it seems to hand altogether.
Anyway, this is not the place to fully investigate all issues, but if someone wants to take that on, we can discuss on https://github.com/T4MVC/T4MVC.

Why do I need to deliver DevExpress.Printing.v14.2.Core.dll

I have implemented a WPF application using DevExpress controls.
When I was finished, I optimized my references in Visual Studio (using Resharper). I have the following references left:
DevExpress.Data.v14.2.dll
DevExpress.Mvvm.v14.2.dll
DevExpress.Xpf.Core.v14.2.dll
DevExpress.Xpf.Grid.v14.2.dll
DevExpress.Xpf.Grid.v14.2.Core.dll
DevExpress.Xpf.Ribbon.v14.2.dll
When starting the application on a clean OS, it crashes. With Process Monitor, I find that it is looking in 10 different places for DevExpress.Printing.v14.2.Core.dll and cannot find it.
That DLL is 3 MB in size and I'd like to avoid to deliver it, if possible.
Dependency walker seems to not work well for .NET.
I have read DevExpress about required libraries, but that is for XtraReports, which I'm not using in my application.
Why does my application look for that DLL if it is not referenced?
Found the answer using JetBrains dotPeek:
DevExpress.Xpf.Core.v14.2.dll and DevExpress.Xpf.Grid.v14.2.dll both have a reference to DevExpress.Printing.v14.2.Core.dll.
Your application contains the DXGrid. Thus, according to the DXGrid's required Redistributable Assemblies list, the DevExpress.Printing.v14.2.Core.dll assembly contains classes that allows to implement the functionality for DXGrid's printing and exporting based on DXPrinting library.

Satellite assembly is not picked up by ASP.NET app

I have a web project called "TestResourceApp" with Labels.resx in App_GlobalResources folder. I want to add another language by creating a satellite assembly.
Here are the steps I took to create the satellite assembly. The default text always get displayed. What did I do wrong ?
1) Create Labels.fr.resx in a different folder.
2) Generate resource file:
Resgen Labels.fr.resx TestResourceApp.App_GlobalResources.Labels.fr.resources
3) Generate satellite assembly:
AL /t:lib /embed:TestResourceApp.App_GlobalResources.Labels.fr.resources /out:french.dll /c:fr
4) Copy french.dll to TestResourceApp/bin/fr
I have uiculture set to auto in web.config and I have change the language on the browser.
I was able to use this page to solve some satellite assembly issues I was having. I'll throw in a few more things to check.
It's helpful to decompile the "neutral" assembly and see how it's put together. A tool like ILDASM.exe is helpful for this purpose. Once you get it decompiled, look through the text output for ".mresource", and you should see one with your naming. For example, if you add a resource to a Visual Studio project, they're named MyAssemblyName + ".Properties.Resources" + a language (if any) + ".resources" Examples:
MyAssembly.Properties.Resources.resources (neutral language)
MyAssembly.Properties.Resources.en-US.resources (English (US))
In my case, I had the file named properly, and in the appropriate folder (such as Bin\en-US). I was able to verify that much by using ProcMon.exe (by the SysInternals guys) and could see the worker process finding and reading in my DLL file (instead of just saying "PATH NOT FOUND"). However, it was not finding the resource by the name that it expected it to. That's when some disassembly helped to get to the bottom of the naming problem.
So, use ProcMon.exe to narrow down the kind of problem you might have. Hopefully that's helpful to someone.
It's complicated but here are a few tips for those who run into this problem:
Try to include the resx in the web project and let VS do the job for you.
Reflector is your friend. Compare satellite assemblies you created and those created by VS.
If you web app is targetting ASP.NET 2.0, you should use Resgex and AL that come with .net 2.0. Open the assemblies in Reflector and check the "references". It should reference mscorlib version 2.0.
If you deploy your web app using web deployment project, make sure the namespace for the resources in your satellite assemblies is correct. Again, compare with what VS creates. In my case, I used the wrong tool to generate the designer.cs file because I wanted them to be accessible from a different assembly. Make sure you are using GlobalResourceProxyGenerator. Otherwise, the namespaces won't match and the deployment code will not be able to find your resource. The namespace in the designer.cs should simply be "Resources", not "XXXX.App_GlobalResources"
Did you have set enableClientBasedCulture to true in globalization ?

What makes an ASP.NET project an application vs library?

I am inheriting some ASP.NET code (I am an OS guy, not a web dev (yet ;-)). The solution has been re-factored and there are multiple projects (libraries and asp.net sites) in it. Aside from the libraries, there are two asp.net projects (called MAINSITE and SUBSITE). Only MAINSITE is being used as the official site (as an asp.net site), and MAINSITE has a depency on the code in the SUBSITE asp.net site, but doesn't use the site itself. I am trying to figure out how to clean this up and convert SUBSITE into a library.
My quick question is, whenever I debug the MAINSITE (set as default), it runs two asp.net processes: MAINSITE and SUBSITE. And so, at the very least, how can I avoid this? Is there a quick/temporary solution to this?
My detailed question is this:
What makes an asp.net site an asp.net site? For instance, in C the difference between an dll and exe could be defined (superficially anyway) as the presence of a main, and potential export information for the library (among other things, of course). If I were to convert an exe to dll I might:
1. remove the main code
2. make sure the public interface was correct (and exported correctly)
3. convert the makefile to build a dll rather than an exe.
Can someone point me to some similar steps for asp.net to .net lib?
Maybe:
1. get rid of index.aspx
2. get rid of web.config
3. any *.cs files to remove?
4. how do I change the properties?
5. any gotchas?
Thanks so much for your help.
Details: Visual Studio 2008/.NET 3.5
There are many, many components to make an application run as an ASP.Net application. However, in terms of your actual Web Application project, there's really not that much difference between it and generic library code except for the fact that much of your code relies on the existence of the HttpApplication runtime.
Any code that utilizes the System.Web (especially System.Web.UI) is going to be suspect in terms of having this dependency. For example, all the code in page or webcontrol event handlers (Init, Load, PreRender, etc.) relies on the fact that there is an HttpHandler (running inside an HttpApplication) raising these events. If you run the same WebControl out of a library that's not in an ASP.Net project, none of this will ever happen and the control will be useless. However, that exact same library would be quite functional if executed in the context of an ASP.Net process.
It really boils down to what process you're running the library in. In most cases, ASP.Net processes are spawned by IIS, although it is possible to host an ASP.Net process in other types of programs as well.
There isn't a simple 5-step process for converting a web project to a library unfortunately. But as a rule of thumb, webcontrols, .aspx and .ascx codebehind aren't going to convert.
For a more detailed look at what makes code into an ASP.Net program, see Rick Strahl's "A Low level look at ASP.Net".
If you go to "File" > "New" > "New Project..." and then click on the (assuming you're using C#) "Visual C#" in the list on the left, you're given the ability to create a "Class Library" project. You can extract all the relevant code to one of these and then reference in in your "MAINSITE".
You will need to reference it in the "References" section of your MAINSITE project and may need to import your library project using the import keyword.

ASP.Net resource files

I'm using selenium to run some functional tests on the UI for our current application.
I want to ensure that strings from the resource files in the Web project are being displayed at the correct time and place.
Simple (I thought) all I have to do is reference the assembly of the web application and assert that the text selenium is reading from the UI matches the test in the approriate resource file.
The problem is the ASP.Net does some precomilation processing on the resource files and compiles them into an assembly called App_GlobalResources, which isn't created by the normal build process so the functional tests fail because that can't find the App_GlobalResources assembly to look the string up from.
So, any suggestions? Do I need to abandon the App_GlobalResources approach and do something manual that I have control over?
Do you understand the problem or do I need to provide more info?
My interim solution is to use SVN:Externals to pull a copy of the resx files into the test project.
I can then access them via
ResourceManager resource = new System.Resources.ResourceManager("My.Web.Namespace.resources.ImageUrls", Assembly.GetExecutingAssembly());
Its ugly because I already have a reference to the webproject (which I can probably remove now...) and I don't like mixing source files between projects. It just feels like asking for trouble but until someone suggests something better this will have to do.
Have you considered moving your GlobalResources into a separate assembly and then referencing that from both your web project and your test project? This is quite easy to do in VS 2008, and achievable but a little more difficult in VS 2005.
I was able to solve a similar problem using that approach.

Resources