I’ve gotten the error message “Could not load file or assembly ‘Microsoft.Web.Infrastructure, Version=126.96.36.199…’ a few times lately when deploying new ASP.NET MVC5 projects to an IIS7.5 or IIS8 web server via the Web Deploy method within Visual Studio 2013, so I thought I’d put up this quick article on how to resolve it.
This error occurs for me when publishing a new MVC5 project to a web server (it does not occur when previewing the project locally from my machine). Initially, after deploying, I’m greeted with the very vague error message:
This message of course has no detail since I’m viewing from a remote machine, which by default won’t get error detail. To resolve this, I can follow the instructions in the error message above to enable detail remotely or I can view the error message directly by visiting the page from the web server itself:
This is a bit more helpful. The error message is essentially saying that it needs a file on the web server that isn’t there. From researching this error message, many articles will mention that the Microsoft.Web.Infrastructure reference isn’t in your project and adding it will fix your issue. Well, it was in my project, so that solution wasn’t right. I could just copy the file manually, but that also didn’t feel right.
Instead, the solution is incredibly simple. Simply click on the Microsoft.Web.Infrastructure reference within your project and within its properties, set “Copy local” to “True.” This will force the file to be copied to the server upon deployment.
Re-publish your application to the web server and the issue should now be resolved!