Monday, March 12, 2012

Deploying ASP.Net MVC 3 to Azure - Could not load System.Web.WebPages

"Could not load file or assembly 'System.Web.WebPages, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"

This was the error I got after hosting an ASP.Net MVC 3 application to Windows Azure. This seems straight forward.The bin folder don't have the mentioned dll. When I checked my web.config I was not able to see any reference to version of System.Web.WebPages .The confusion started from there. Who is in need of the version of system.web.webpages.dll. As debugging in Azure from local machine is difficult, I had to do remote desktop to Azure machine. Still no clues. In the web.config,I could see that I am referring the WebPages dll which is in version and in the bin folder I have the right version.

I tried to locate the fusion log viewer in the Azure machine .But no luck. Not able to locate 1fuslogvw.exe there as it is available with sdk only.

Then I tried to create the registry entry2 to log the assembly binding .Due to some unknown reasons it was not working.Finally I had to check the references of each assembly which are present in the bin folder usnig reflector.

Luckily the first assembly I selected in the reflector was System.Web.MVC where it was referring version of system.web.webpages.dll. Then I checked where from the webpages dll came ? it was interesting .There are 2 folders in my dev machine where the webpages dll is present in different versions.

C:\Program Files\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies
C:\Program Files\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Assemblies

Now things became more clear. I had installed MVC 4 in my development machine and its  System,Web.MVC.dll needs webpages dll in Some how that version of webpages added to my MVC 3 project and took my half day.

1Location of fusionlogvw.exe - C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin
2HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion!EnableLog] (DWORD) to 1
3Location of System.Web.MVC.dll - C:\Program Files\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies

No comments: