Saturday 22 February 2014

File Load Exception: Could not load file or assembly ASP.NET MVC

My first post :)

This is a common exception that happens when we upgrade an installed package. So why is this throwing this exception.

FileLoad Exception
Could not load file or assembly 'BLToolkit.4, Version=4.1.10.2158, Culture=neutral, PublicKeyToken=b1d3f6ab3aadaca3' or one of its dependencies.
The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)


I got this exception when I tried to upgrade to BLToolkit version 4.1.21. In order to get a detailed description for this exception there is a handy tool Fuslogvw.exe (Fusion Log Viewer /Assembly Binding Log Viewer) which is automatically installed with Visual Studio and with the Windows SDK. The Assembly Binding Log Viewer displays details for assembly binds that Visual Studio fails to bind at runtime.

To enable Fusion Log viewer

If you have Visual Studio installed on your computer: On the taskbar, click Start, click All Programs, click Visual Studio, click Visual Studio Tools, right-click Visual Studio Command Prompt, and then click Run as administrator from the shortcut menu.

At the administrator command prompt, type

fuslogvw

http://msdn.microsoft.com/en-us/library/e74a18c4%28v=vs.110%29.aspx

Assembly Binding Log Viewer- Figure 1

Add the following registry values to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion

DWORD ForceLog set value to 1
DWORD LogFailures set value to 1
DWORD LogResourceBinds set value to 1
String LogPath set value to D:\FusionLogs\ (optional)

Make sure to include the backslash after the folder name. You can also give custom folder path in Log Location in the popup window.
After configuring and verifying the Log Viewer is enabled; start the application in visual studio debug mode.
You will get list of all assemblies loading for that application in the Log Viewer. Select the assembly having conflict issues and click on View Log button in the popup.

Listing both versions - Figure 2
Two version of assembly is loaded, select the application and click on View Log. It will open in a new browser window with detailed description of error.

LOG: Assembly Name is: BLToolkit.4, Version=4.1.21.0, Culture=neutral, PublicKeyToken=b1d3f6ab3aadaca3
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: The assembly reference did not match the assembly definition found.
ERR: Setup failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.


Solution

Since after upgrade, the application is trying to load previous version which is not available in the assembly path. So we need to redirect the binding from previous version to newly updated version number.
Add the below code to your web.config.






In Figure 2 it is listing both the versions. After updating web.config, run the log viewer, you will see only the latest version of the BLToolkit package.



Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam aliquam massa quis mauris sollicitudin commodo venenatis ligula commodo.

Related Posts

0 comments:

Post a Comment