29

I've just tried deploying an MVC3 application to our IIS7 hosting environment but I'm being presented wtih the following exception:

Could not load type 'Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility' from assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.TypeLoadException: Could not load type 'Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility' from assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Any suggestions?

The app isn't being bin deployed as I have installed ASP.Net Web pages and MVC3 on the web server itself.

Phil.Wheeler
  • 16,748
  • 10
  • 99
  • 155
  • 2
    Look at http://stackoverflow.com/questions/4723646/asp-net-mvc-3-which-dlls-need-to-be-deployed/4723778#4723778 – Omar Jan 20 '11 at 02:31
  • Just to be clear, I'm not bin deploying this app - I already have MVC3 installed on the server. – Phil.Wheeler Jan 20 '11 at 02:43
  • What other ways are there to deploy an app? – Shawn Mclean Jan 20 '11 at 02:49
  • 4
    @Shawn - If someone says "just bin Deploy it" they mean "deploy the application with the dependencies copied into the application's /bin folder, rather than running an MSI that installs the dependencies into the Global Assembly Cache (GAC)." - Scott Hanselman – Phil.Wheeler Jan 20 '11 at 02:50

4 Answers4

54

This is because Microsoft.Web.Infrastructure is not in your GAC. You need to add this reference to your project. Right click the reference and go to properties then set copy to local to true.

Copy Local

Output (Ignore the Ninject and NCU):

alt text

Shawn Mclean
  • 56,733
  • 95
  • 279
  • 406
  • I've checked C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.Web.Infrastructure\v4.0_1.0.0.0__31bf3856ad364e35 and the DLL is definitely there. I don't have this dependency in my project as it stands. – Phil.Wheeler Jan 20 '11 at 02:30
  • You may also have to reference a bunch of other stuff too. Stuff like Razor, System.Webpages, etc. It wont be in your project, but you can reference it by adding from the framework assemblies. – Shawn Mclean Jan 20 '11 at 02:31
  • Should that not be included in the System.Web.MVC DLL? – Phil.Wheeler Jan 20 '11 at 02:34
  • This problem happened to me yesterday, I'll update my post with all the ddls that went into the output directory. – Shawn Mclean Jan 20 '11 at 02:35
  • Just copied and deployed the local version of the Microsoft.Web.Infrastructure DLL and the error still persists. – Phil.Wheeler Jan 20 '11 at 02:36
  • @Phil.Wheeler Take a look at the answer linked by Omar in the question comments. It appears to outline all of the required references. – Nathan Taylor Jan 20 '11 at 02:37
  • I've gone over that and tried adding in System.Web.WebPages.Deployment.dll but the problem still persists. – Phil.Wheeler Jan 20 '11 at 02:48
  • My reference was added during our upgrade from MVC 2 to MVC 5 (done in incremental stages...) It was lost, either during a source control merge operation or due to ReSharper's over-zealous deletion of "unused" references. At any rate, this answer helped, since I already had the package installed and could not remove and reinstall it. – Zarepheth Dec 18 '14 at 16:26
11

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 packages.config file

<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />

and ran the command again

PM> Install-Package Microsoft.Web.Infrastructure

After this, now it works fine.

Riaan
  • 3,423
  • 4
  • 30
  • 36
  • 3
    Even if a package is installed, you can force re-installation rather than doing what you have done using the command: Update-Package Microsoft.Web.Infrastructure -Reinstall – Tyler Durden Jul 10 '15 at 05:47
  • 1
    For me the package was removed from the references and not from the packages list either. So I added it back in as a reference (had to browse for the package installed locally with my project) – wecky Jun 27 '18 at 08:58
  • 1
    I have followed all the above steps and now my code is working fine, Thanks. – Varinder Singh Baidwan Oct 21 '20 at 13:05
6

Microsoft.Web.Infrastructure is now a Nuget package, and it can be added to your project to enable bin directory deployments --

http://nuget.org/packages/Microsoft.Web.Infrastructure

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
Jason
  • 15,915
  • 3
  • 48
  • 72
  • 3
    I have the package installed in my project, but the project does not reference the DLL. I'm guessing that an overzealous application of ReSharper's "remove unused references" may have deleted more than it should... – Zarepheth Dec 18 '14 at 14:20
3

Make sure that the root web.config file on your server (located somewhere like here: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config) has the following entry:

<configuration>
  <location allowOverride="true">
    <system.web>
      <fullTrustAssemblies>
        <add
          assemblyName="Microsoft.Web.Infrastructure"
          version="1.0.0.0"
          publicKey="[bunch of letters and numbers]"
        />

If it's missing then it means that somebody messed with your .NET 4 installation.

marcind
  • 52,944
  • 13
  • 125
  • 111