I tried to upload my web site to a server. It was working fine with my local host, so I uploaded everything in my localhost
wwwroot folder to the server and changed the connection string.
But there is this error:
Exception information: Exception type: InvalidOperationException Exception message: The pre-application start initialization method Start on type RouteDebug.PreApplicationStart threw an exception with the following error message: Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=18.104.22.168, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.. at System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) at System.Web.Compilation.BuildManager.CallPreStartInitMethods() at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=22.214.171.124, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. at RouteDebug.PreApplicationStart.Start()
The project was
What should be done to resolve this error?
You will need to include the dll with your project and add a reference to it as well.
Here is a link to a similar issue already on Stack:
MVC3 Deployment Dependency Problems
I found that even though it worked on my dev box, the assembly wasn’t added to the project. Search for Microsoft.Web.Infrastructure in NuGet and install it from there. Then, make sure it has Copy Local selected.
Install AspNetMVC3ToolsUpdateSetup downloaded from here would solve this problem without adding reference
It turns out after doing a Reference Cleaning, it removed
Microsoft.Web.Infrastructure, but not from the packages.config file. After trying to add it again using the
Package Manager Console, Visual Studio says that it is already installed which is false because it was removed.
I then removed the line of code in the
<package id="Microsoft.Web.Infrastructure" version="126.96.36.199" targetFramework="net45" />
and ran the command again
PM> Install-Package Microsoft.Web.Infrastructure
After this, now it works fine.
Despite the number of answers I’ll add another one which IMHO makes the things a bit clearer.
Apparently, it was referenced by your project and suddenly disappeared. A number of reason may exists but the important thing is that despite you may have enabled Automatic Package Restore in Visual Studio by:
- Manage NuGet packages for solution (context menu in Solution Explorer),
- Allow NuGet to download missing packages (settings),
- Automatically check for missing packages during build in Visual Studio (settings),
certain packages may require a manual reinstall. I am not aware what confuses NuGet, maybe manually removing a reference, but here is the solution I usually apply in such cases. The following PM Console helps restoring a package while preserving the original version (not updating to possibly existing new one):
Update-Package Microsoft.Web.Infrastructure -Reinstall
Version preservation may be required if you do not want to accidentally overwrite an existing package with its newer version which possibly removes “old” functionality you may have used in your project.
And, as a proof, despite a bit lengthy one, that the version does not change, here’s the output when the command is executed:
PM> Update-Package Microsoft.Web.Infrastructure -Reinstall Attempting to gather dependencies information for multiple packages with respect to project 'Samples.NuGet\DemoApp\DemoApp', targeting '.NETFramework,Version=v4.5.2' Attempting to resolve dependencies for multiple packages Resolving actions install multiple packages ... Package removal starts here... ... Removed package 'Microsoft.AspNet.Web.Optimization 1.1.3' from 'packages.config' Successfully uninstalled 'Microsoft.AspNet.Web.Optimization 1.1.3' from DemoApp Removed package 'WebGrease 1.5.2' from 'packages.config' Executing script file 'D:\Projects\DemoApp\packages\WebGrease.1.5.2\tools\uninstall.ps1' Successfully uninstalled 'WebGrease 1.5.2' from DemoApp ... More package removals here. Omitted for brevity... ... Removed package 'Microsoft.Web.Infrastructure 188.8.131.52' from 'packages.config' Successfully uninstalled 'Microsoft.Web.Infrastructure 184.108.40.206' from DemoApp ... More package removals here. Omitted for brevity... ... Removed package 'Antlr 220.127.116.1104' from 'packages.config' Successfully uninstalled 'Antlr 18.104.22.16804' from MvcLenseApp Package 'Antlr.22.214.171.12404' already exists in folder 'D:\Projects\Lense.Mvc5\packages' --- Install packages (in reverse order) --- Package 'Antlr.126.96.36.19904' already exists in folder 'D:\Projects\DemoApp\packages' Added package 'Antlr.188.8.131.5204' to 'packages.config' Successfully installed 'Antlr 184.108.40.20604' to DemoApp ... More package installs here. Omitted for brevity... ... Package 'Microsoft.Web.Infrastructure.1.0.0' already exists in folder 'D:\Projects\Lense.Mvc5\packages' Added package 'Microsoft.Web.Infrastructure.1.0.0' to 'packages.config' Successfully installed 'Microsoft.Web.Infrastructure 1.0.0' to MvcLenseApp ... More package installs here. Omitted for brevity... ... Package 'WebGrease.1.5.2' already exists in folder 'D:\Projects\DemoApp\packages' Added package 'WebGrease.1.5.2' to 'packages.config' Executing script file 'D:\Projects\DemoApp\packages\WebGrease.1.5.2\tools\install.ps1' Successfully installed 'WebGrease 1.5.2' to DemoApp Package 'Microsoft.AspNet.Web.Optimization.1.1.3' already exists in folder 'D:\Projects\DemoApp\packages' Added package 'Microsoft.AspNet.Web.Optimization.1.1.3' to 'packages.config' ... End of package re-install. ... Successfully installed 'Microsoft.AspNet.Web.Optimization 1.1.3' to DemoApp PM>
Resharper detected Microsoft.Web.Infrastructure as an unused reference an so I deleted it. Locally was working fine but then I got the same error after publishing to dev.
Conclusion, beware when deleting references marked as unused by Resharper
Try installing Web Platform from https://www.microsoft.com/web/platform/
Hope it helps.
I had a similar problem. NuGet showed the package successfully installed, but the reference was not added to my project.
<PM> Install-Package Microsoft.Web.InfraStructure also didn’t help as the package manager kept saying it’s already installed
I finally added it manually by editing the csproj file and adding these lines:
<Reference Include="Microsoft.Web.Infrastructure"> <HintPath>..\packages\Microsoft.Web.Infrastructure.220.127.116.11\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath> <Private>True</Private> </Reference>
That solved the problem.
You need to download the ASP.NET MVC framework on the server hosting your application. It’s a quick fix just download and install from here (This is the MVC 3 framework http://www.asp.net/mvc/mvc3), then boom you are good to go.
Microsoft.Web.Infrastructure.dll was missing from the bin folder, it wasn’t set to copy local in the project.
Copied the dll from another project in the solution and the page loads.
Very easy solution:
In Visual Studio, go to Tools/Library Package Manager/Package Manager Console
<PM> Install-Package Microsoft.Web.InfraStructure
Have a nice time
Here was my scenario.
I had a multi project solution containing projects A, B, C .. N.
Project B was a code library that contained a factory for
The project would run as expected in development, but when publishing to our test environment I was getting the error you were encountering:
Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=18.104.22.168, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
What had happened was through nuget package manager, I had accidentally installed “Microsoft ASP.NET MVC” which installed dependencies for:
Low and behold, Microsoft.AspNet.WebPages depends on “Microsoft.Web.Infrastructure”.
My solution was uninstalling the three packages mentioned above (MVC, Razor, WebPages) then right click references > add reference > Assemblies > Extensions > System.Web.MVC.
I don’t know what happened with my project but it referenced the wrong path to the DLL. Nuget installed it properly and it was indeed on my file system along with the other packages but just referenced incorrectly.
packages folder exists two directories up from my project and it was only going up one by starting the path with
..\packages\. I changed the path to start with
..\..\packages\ and it fixed my problem.