One of the most common problems reported regarding Windows Azure Web Sites is “Assembly Loading” issue. Here are some of the forum posts.
If you site works well locally. However, after you deployed to WAWS, it doesn’t work anymore, then you need to consider about this. It is really easy to isolate the problem, just merge follows into your web.config,
And you should see the error in your browser.
Could not load file or assembly xxxxxx, Version=x.x.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxx or one of its dependencies. The system cannot find the file specified.
The hosting environment of WAWS contains a standard installation of .Net framework 2.0 to .Net framework 4.5. If your application referenced assemblies which is not build in .Net framework, you have to “include” them with your deploy package. Even these are Microsoft assemblies.
Here is the steps to deploy the referenced assemblies with your application.
1. I have a project need to access Windows Azure Storage Table, to implement this feature, I referenced Microsoft.WindowsAzure.StorageClient.dll.
2. In Visual Studio, Find the referenced assembly in “Solution Explorer”, In the “Properties” window, set the “Copy Local” to “True”.
Another common reason is WAWS runs 32bit IIS worker process running on X64 system. So, if the assembly you referenced is not platform neutral, and unfortunately, you referenced the X64 bit version. You will hit the problem as well. In case of this, you should see follow message after merging follows into your web.config,
Exception message: Could not load file or assembly ‘xxxxxx or one of its dependencies. An attempt was made to load a program with an incorrect format
February 27, 2017
In most cases .NET manages to solve the DLL hell problem pretty well, but sometimes it all falls apart, and when it does in best case scenario we see something like this:
The much worst case is this:
This post is an analysis of why this happens and how to diagnose it:
As the old saying goes:
There is a log for that.
In this case, it only needs to be turned on:
Enable assembly binding logging (Fusion log)
Assembly binding is turned on using those registry settings:
- HKEY_LOCAL_MACHINESOFTWAREMicrosoftFusionEnableLog — Type of DWORD
- HKEY_LOCAL_MACHINESOFTWAREMicrosoftFusionForceLog — Type DWORD
- HKEY_LOCAL_MACHINESOFTWAREMicrosoftFusionLogFailures — Type DWORD
- HKEY_LOCAL_MACHINESOFTWAREMicrosoftFusionLogResourceBinds — Type DWORD
- HKEY_LOCAL_MACHINESOFTWAREMicrosoftFusionLogPath — Type String
To enable logging the first four should be set to 1 and the last to a existing directory path (it should also end with an ).
It can be done manually with the use of regedit.exe , but since it can be automated, here are the scripts:
CHECK THE FILES CONTENT BEFORE RUNNING! (they are just text files) DON’T RUN THIS OR ANY OTHER SCRIPT WITHOUT CHECKING. MODIFYING REGISTRY REQUIRES ADMINISTRATOR PERMISSIONS, SO A LOT OF HARM CAN BE DONE WHEN RUNNING A SCRIPT FORM A NOT TRUSTED SOURCE.
After enabling assembly binding logging, there are two ways to continue:
I’m having another of these «Could not load file or assembly or one of its dependencies» problems.
Additional information: Could not load file or assembly ‘Microsoft.Practices.Unity, Version=1.2.0.0, 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)
I have no idea what is causing this or how I could debug it to find the cause.
I’ve done a search in my solution catalogs .csproj files, and every where I have Unity I have:
Reference Include=»Microsoft.Practices.Unity, Version=2.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL»
Can’t find any reference anywhere which goes against 1.2.0.0 in any of my projects.
Any ideas how I should go about solving this?
I would also appreciate tips on how to debug problems like this in general.