Friday, May 14, 2010

ASP.Net 4 and IIS6

A few days ago I posted about how to switch frameworks (to ASP.Net 4) on a single website  (among many) without having to restart IIS.  Well, Now I ran into another issue:  “Connection Reset” error from the browser. Tried a bunch of things, including checking logs, recreating the App Pool, rechecking all website settings, etc….  Nothing. 

After some googling, it turns out that it is not enough to Install 4 but it has to be manually “enabled”.  I’ll give you the quick run through but here is the post that that goes into more detail about the fix.

1) Confirm that ASP.Net 4.0 is disabled.
cscript iisExt.vbs /ListFile

If the entry for .Net 4 has a 0 on the left, then you need to enable it

2) Enable .Net 4 extension

cscript iisExt.vbs /EnFile C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll

Run the first command and you should have a 1 instead of 0 next to .Net 4.


That did it for me, I hope it works for you as well.


Tuesday, May 11, 2010

Using IIS Virtual Path: Upgrade a site to .Net 4 without restarting IIS

Recently, our project was upgraded to ASP .NET 4.0. Upgrading Dev environments was a breeze, however, in production, only one website needed to run ASP.NET 4.0 while the other websites needed to be left alone.

First thing I tried doing was go to the properties dialog of the website and switch the targeted framework.


This is the warning message I got:


Naturally I cancelled that and attempted running the suggested command, but the problem was how to find out the "IIS Virtual Path" bit?.

I found this answer in this Stack Overflow:

The answer basically boils down to executing "aspnet_regiis -lk" command to find out your website ID and then run the command suggested by the warning message.

My problem running "aspnet_regiis -lk" was that I got an incomplete list of IDs and also I didn't know which ID corresponded to the Website I wanted to work on.

A co-worker pointed out an easier way to find the IDs for your websites: click on the "Website" node (folder) in IIS. Now on the right side you should see a list of all websites with their "Identifiers", State, IPs and ports.


Cool! Now I can run my command with the correct ID.

1) Navigate to C:\Windows\\Framework64\v4.0.30319
2) Execute aspnet_regiis.exe -norestart -s “W3SVC/YOURWEBSITEID/root

Note: If your application is not at the root of the website, then you need to add the AppName at the end: “W3SVC/YOURWEBSITEID/root/AppName

Now, go to your website properties and check that your targeted framework is ASP.NET 4.0 and voila!


Wednesday, May 5, 2010

VS2010 New feature Call Hierarchy and ReSharper's Call Tracking

I've been playing with VS2010 for a couple of days now, and I just recently stumbled upon an awesome features that every Dev will love: "Call Hierarchy".

In simple words, you can now view where your methods/properties are being called from. Now, you might say, "We've had that for a while, its called 'Find usages'", Well, this is better: You can actually view and go through the call tree graph WITHOUT having to be in debug mode. As Borat would say: "Itzanice!"  Scott Gu has a really nice post about it, go see it.

Playing around with it, I noticed that ReSharper also has its own implementation of it: “Call Tracking”.  And, it is actually better  than the one with VS2010.  So, if you have ReSharper, go to a method and do Ctrl+Shit+Alt+A , then select “Incoming Calls”. A new window will open up showing all callers to this functions and the tree graph. It’s so cool!

 Select “Incoming Calls”

New Windows opens up with all callers and the call tree

You might have also noticed that you can select “Outgoing Calls” which is the exact opposite of viewing all the callers, it’s a “Go to definition” on steroids!

As ReSharper puts it, Call Tracking is “an all-out Find Usages and Go To Declaration”.  Go check out their post about it to find out more details.

Tuesday, May 4, 2010

Upgrading your build server to use .Net 4 + Nant

At work we use + Nant for our continuous integration. Recently we have upgrades to VS2010 and .Net 4.0 (awesome so far). Alas, as soon as we converted our solution to .Net 4.0, our build server broke! After googling and wrestling for 2 days with build errors, I finally got the build server running again. I found most of my questions on Stack overflow, however I had this "AL exited with code 128" build error that I could not get past and it was driving me crazy! So, below are the steps to upgrade to .Net 4.0 and to solve the "AL" error message (that hopefully you won't get):

First thing. You DO NOT need to intall VS2010 in the build server like many people think. You do have to install the latest Windows SDK. (I believe 7.0)

1) Install .Net 4.0 Framework.

2) Install latest Windows SDK.

Install the latest Windows SDK, then go to the registry and copy the key "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0" and rename all instances of 7.0 to 7.0A. The Build server is going to look at that path in order to get the "Installation Folder key". Alternatively, You can copy the text below into a notepad and save it as "whatever.reg", then run it and it should import the key and subfolders into the registry.

*~~~~~~~~~~~~~~~~~~~~ Copy everything below this line ~~~~~~~~~~~~~~~~~~~~~~

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0A\\"
"ProductName"="Microsoft Windows SDK for Visual Studio 2010"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx35Tools]
"ComponentName"="Windows SDK .NET Framework 3.5 Multi-targeting Utilities"
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx40Tools]
"ComponentName"="Windows SDK Tools for .NET Framework 4.0"
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\NETFX 4.0 Tools\\"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-SDKTools]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\"
"ComponentName"="Windows Common Utilities"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-Win32Tools]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\"
"ComponentName"="Windows Utilities for Win32 Development"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-WindowsHeadersLibs]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0A\\"
"ComponentName"="Windows Headers and Libraries"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-WinSDKIntellisenseRefAssys]
"InstallationFolder"="C:\\Program Files\\Reference Assemblies\\"
"ComponentName"="Windows Intellisense and Reference Assemblies"

*~~~~~~~~~~~~~~~~~Do not include this line~~~~~~~~~~~~~~~~~~~~~

3) Modify your Nant.exe.config file.

Towards the end of your Nant.exe.config file, modify the <startup> section to add .Net 4.0 as a supported Runtime:

<supportedRuntime version="v4.0.30319" />.

Also, under the <properties> section, add a property:

<property name="nant.settings.currentframework" value="net-4.0" />

This will make your builds default to that framework. You can also put this property in your projects Nant file, so you can tell each project what version to target. Finally, you need to add the .net4.0 framework node. Here is a link to that configuration section:

4) Review the Build section of your Nant file

I was using the msbuild task for NantContrib. That still works, but if it doesn't, you can always use the <exec> task and call msbuild.exe like so:

<property name="msbuild.exe" value="C:\WINDOWS\Microsoft.NET\Framework\v4.0\MSBuild.exe" />    

<exec program="${msbuild.exe}">        
        <arg line="/property:Configuration=${YourSolutionConfigurationHere}" />         
        <arg line='"${YourSolutionFileFullPathHere}"' />         
        <arg value="/target:Rebuild" />         
        <arg value="/verbosity:normal" />         
        <arg value="/nologo" />         

5) Random Errors

I ran into some weird build errors: "error MSB6006: "AL.exe" exited with code 128" That's it, not helpful at all. I did some googling and came up with few answers. Here are the links: msdn help and forums.  I wrestled with that error for a full day, studying the "detailed" and "diagnostic" logs, but all it did is pointing me to the assembly that failed building. No specific error. I could not even duplicate it on my local box.

Finally, I decided to try the suggestion about the "resource" files naming convention in the forum link, and... alleluia! my build started working. I don't know what's up with the build failing because of the resource name, still working on that, but my immediate goal was to get the build working.

StackOverflow related posts:

Hope this helps someone else out there.