Friday, June 29, 2012

The "Could Not Load File or Assembly" exception


Many a times, when one has to start building up on a cloud project, this exception is faced. The scenario goes like this.

I take the latest version of the code from the repository and build it. On build it gives me the following exception.





The reason for this exception is that the solution was previously built using old dlls eg. dlls of the SDK 1.4. Probably when it was built this was the latest version available, but on your machine you have the updated ones in your GAC, say dlls of the SDK 1.7.

Till Windows SDK version 1.6, the required assemblies were stored at:
C:\Program Files\Windows Azure SDK\v1.6\ref

For the SDK version 1.7, the assemblies are stored at:
C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\2012-06\ref

Ok.Back to the exception. You just have to follow these simple steps:

1.  Clean the solution.

2.  In the 'References' folder, remove the reference of the old 
    version and add reference of the new version of the dll.

    In case of the StorageClient.dll, make sure you update the 
    references of the other related dlls too. i.e. 
    Microsoft.WindowsAzure.ServiceRuntime.dll and 
    Microsoft.WindowsAzure.Diagnostics.dll

3.  In all the config files (web.config & app.config), make sure to
    change the versions in places like:

    to

That's it! In 3 simple steps, you're ready to go! Build the project now and it executes just fine! :)

No comments:

Post a Comment