How to resolve the “Could not load file or assembly” Issues on Windows AZure Web Sites

 

One of the most common problems reported regarding Windows Azure Web Sites is “Assembly Loading” issue. Here are some of the forum posts.

 

https://social.msdn.microsoft.com/Forums/en/windowsazurewebsitespreview/thread/cab09b05-e09f-420a-9ad3-87e6ab12e3f0

https://social.msdn.microsoft.com/Forums/en-US/windowsazurewebsitespreview/thread/d361a111-4ba9-48b1-8732-1a55ab7b59bb

https://social.msdn.microsoft.com/Forums/en-US/windowsazurewebsitespreview/thread/608214eb-916a-4f6c-bb81-2fd3516ced24

https://social.msdn.microsoft.com/Forums/en-US/windowsazurewebsitespreview/thread/6191e663-d014-4a7e-8885-8823f6d1a780

https://social.msdn.microsoft.com/Forums/en-US/windowsazurewebsitespreview/thread/6f68a726-bddb-4312-ae75-043b775da271

https://social.msdn.microsoft.com/Forums/en-US/windowsazurewebsitespreview/thread/e0b86ebe-2a47-4626-bc0d-5c05b39bff7b

 

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,

 

<system.web>

         <customErrors mode="Off"/>

</system.web>

 

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,

 

<system.web>

         <customErrors mode="Off"/>

</system.web>

 

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

 

See you next time.

 

Wei Zhao from APGC DSI Team