Could not load file or assembly Microsoft. Web. Infrastructure

If you work on Web Applications and using Asp.Net to power it you may find this error on run time, application might compile perfectly but generates the runtime error stating:

Could not load file or assembly ‘Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.

 

Error Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

 

It appears that Microsoft.Web.Infrastructure.dll is not being installed in the GAC, even if .net (4.0 or 4.5 or other) are installed successfully on Windows Server. On localhost (typically Windows client), it seems like it is being in the GAC when the tools/platform (Visual Studio etc.) are installed.

 

Possible Fix 1

Run the following command in the Package Manager Console. (If you are using Visual Studio, this can be reached via menu options “Tools –> Library Package Manager –> Package Manager Console:)

PM> Install-Package Microsoft.Web.Infrastructure

You will see the following messages if it is successfully installed.

Successfully installed ‘Microsoft.Web.Infrastructure 1.0.0.0’.
Successfully added ‘Microsoft.Web.Infrastructure 1.0.0.0’ to Web.

If you see this message you are good to go. Shoop. But in case it does not work try the next one.

 

Possible Fix 2 (Less Technical)

When you do above fix package manager can produce this(non welcoming) message for you:

the package was already installed and assigned to my project.

This is the case when you already have this Microsoft.Web.Infrastructure.dll added in your solution. Go to Window’s explorer and try to search the file by name. Most probably you will find it, copy the path and add it as a reference in project.

Rebuild and Run the project.

Let me know in comments if this does not work or some other solution works for you.