4

I am trying to deploy a fresh MVC3 project to an Azure website.

Steps:

  1. Create a new MVC3 Internet Application in VS 2012 with Razor View Engine. Add to the web.config file.
  2. F5 to build and debug locally, validate that site loads in local debug.
  3. Create a new azure website and download the publish settings file for the site.
  4. Publish the site using the publish settings downloaded in step 3.

EXPECT>> Site loads as expected when published.

ACTUAL>> "Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference." (full stack trace below)

I know that the sample project used to publish for me out of the box with no errors, but I haven't tried for a year or so.

I've seen some similar errors on Stackoverflow, but the answers are either not relevant or incomplete:

I've been chasing my tail for this for a long time now. Does anyone have any suggestions?

    Server Error in '/' Application.
--------------------------------------------------------------------------------


Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) 
  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.IO.FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error: 


 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.



WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].



Stack Trace: 



[FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   Microsoft.Web.Mvc.ViewEngineFix.PreAppStart() +0

[InvalidOperationException: The pre-application start initialization method PreAppStart on type Microsoft.Web.Mvc.ViewEngineFix threw an exception with the following error message: Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +550
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +90
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +140
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516

[HttpException (0x80004005): The pre-application start initialization method PreAppStart on type Microsoft.Web.Mvc.ViewEngineFix threw an exception with the following error message: Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9877836
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext 
Community
  • 1
  • 1
DanJosef
  • 353
  • 1
  • 3
  • 13
  • I am targetting a windows azure website. I don't think I can install particular versions of MVC there (correct me if I'm wrong!). – DanJosef Dec 31 '13 at 10:41
  • Agreed -- MVC4 seems to work, tho I did need to implement this workaround for another error that came up with the OOB MVC4 project (again, only in azure, not on local tests). Workaround: http://ediblecode.com/blog/dot-net/asp-net-mvc/fixing-multiple-types-were-found-that-match-the-controller-named – DanJosef Dec 31 '13 at 11:32
  • btw Jesse -- If you submit an answer I can mark yours as the answer.. I don't think I can do this with a comment. – DanJosef Dec 31 '13 at 11:33

1 Answers1

4

In your question you state that you're targeting MVC3, but it looks like the Azure machine is not finding the correct version of that assembly. It's finding the MVC binaries. This leads me to believe that MVC3 is not installed on the server you're trying to publish to.

There are a few options available to you:

  1. Upgrade your project to MVC4 and publish the upgraded version.
  2. Apply a set of BindingRedirects in your web.config to redirect MVC3 to MVC4 at runtime

This is the set of binding redirects I think you'll need, there might be others, but you'll get a similar error for each of them:

<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers"
                              publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc"
                              publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="4.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages"
                              publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>
Community
  • 1
  • 1
jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • As discussed in the comments on the OP, Jesse got me on the right path. Azure doesn't seem to like the OOB MVC3 application, so moving to MVC4 got me working again. Note that I needed to implement a separate workaround described [here](http://ediblecode.com/blog/dot-net/asp-net-mvc/fixing-multiple-types-were-found-that-match-the-controller-named) to get the MV4 project working in azure. – DanJosef Dec 31 '13 at 11:57