none
Could not load file or assembly System.Web.WebPages.Razor, Version=2.0.0.0, RRS feed

  • Question

  • I have a cloud service that has two web roles, an asp.net mvc4 website and a web api 2.0.

    I am using Visual Studio 2015 to deploy the cloud service.

    The website is working well in my local or even using azure cloud emulator but when i deploy the cloud service. i get the following error message when accessing the asp.net mvc4 website:

    Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, 

    The detailed error message in the event log:

    Exception information: 
        Exception type: InvalidOperationException 
        Exception message: The pre-application start initialization method Start on type WebMatrix.WebData.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.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).
       at System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures)
       at System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods)
       at System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded)
       at System.Web.Compilation.BuildManager.ExecutePreAppStart()
       at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)

    Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.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)
       at WebMatrix.WebData.PreApplicationStartCode.Start()

    I have System.Web.WebPages.Razor version 3.0 and it is all related dependencies in version 3.0  and all are in the bin directory of the deployed package.

    Any ideas how to fix this ?


    -- ME



    Thursday, August 6, 2015 9:01 PM

Answers

  • Here is how to fix this error:

    1) Open the web.config for the web application.

    2) Before the closing tag of <runtime> tag add the following:

     <!-- fix for razor runtime after upgrade to vs 2015-->
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Razor" culture="neutral" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages.Razor" culture="neutral" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>

    3) Save and close the web.config

    4) Open nuget package manager in VS 2015.

    5) Install the following packages:

    Install-Package WebMatrix.Data
    Install-Package Microsoft.AspNet.WebHelpers
    Update-Package

    6) These commands will install required packages for the new Razor engine version 3.0, The last command will make sure to get all latest nuget updates for related mvc and razor packages.

    7) Clean the solution and rebuild the solution.

    Enjoy.


    -- ME





    Thursday, August 6, 2015 9:07 PM

All replies

  • Here is how to fix this error:

    1) Open the web.config for the web application.

    2) Before the closing tag of <runtime> tag add the following:

     <!-- fix for razor runtime after upgrade to vs 2015-->
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Razor" culture="neutral" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages.Razor" culture="neutral" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>

    3) Save and close the web.config

    4) Open nuget package manager in VS 2015.

    5) Install the following packages:

    Install-Package WebMatrix.Data
    Install-Package Microsoft.AspNet.WebHelpers
    Update-Package

    6) These commands will install required packages for the new Razor engine version 3.0, The last command will make sure to get all latest nuget updates for related mvc and razor packages.

    7) Clean the solution and rebuild the solution.

    Enjoy.


    -- ME





    Thursday, August 6, 2015 9:07 PM
  • This worked for me. Thank you!
    Wednesday, August 21, 2019 7:35 AM