Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, or one of its dependencies

43,300

Solution 1

@ProNotion is right, I have seen more and more packages on Umbraco relying on specific versions of assemblies causing assemblies to conflict especially if two packages need different versions of the same assembly.

So some other tips:

This tool from MS helps diagnose assembly binding problems (http://msdn.microsoft.com/en-us/library/e74a18c4%28v=vs.71%29.aspx).

Adding a runtime / assemblyBinding section to your web.config can work round problems with clashing assemblies (http://msdn.microsoft.com/en-us/library/0ash1ksb(v=vs.110).aspx)

Sometime the assembly doesn't get copied (eg you use msbuild and the assembly isn't included in the project) - so you should also check to see if the assembly made it to the live server.

Solution 2

Have you checked the actual version of System.Web.WebPages.Razor that is currently deployed to your bin folder? I had a similar issue recently in a multi-project solution and one of the projects was using an older version of the assembly via Nuget which happened to be the one that ended up in the bin folder causing a similar error. In fact I'm pretty sure that it's the Umbraco Nuget package copying in the older assembly.

Solution 3

Finally, I have fixed this issue. Blog Engine's(Child application) Razor Script version is 2.0.0.0 and Umbraco(Parent application) 4.1.6 application's Razor script version is 1.0.0.0, i have added the below in child's web.config

<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31BF3856AD364E35" culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>

Once the above added, i get rid of this error and i faced the same dependency errors for the below and i added the respective dependent assembly and the version.

Microsoft.Web.Helpers.dll 
Examine.dll
Umbraco.dll
WebGrease.dll

For the above three dependency will not present in child application's bin folder, you need to copy the dll files from parent bin folder and add it in child bin folder, which will sort all the dependency issues.

For any deploying issues on BlogEngine as virtual directory and Umbraco as parent application, leave your message will help you solve the issue of any different versions.

Solution 4

Please try the following steps.

  1. Check the Version of System.Web.Webpages in your References. Say Your Version is=X.X.X.X

2.In Webconfig

a.Add the assembly first

<assemblies>        
  <add assembly="System.Web.WebPages, Version=X.X.X.X, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>

b.Bind the assembly for runtime

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-X.X.X.X" newVersion="X.X.X.X"/>
  </dependentAssembly>        
</assemblyBinding>

3.Make sure you have added correct key

<appSettings>
    <add key="webpages:Version" value="X.X.X.X"/>
</appSettings>

This worked for me. Hope It'll help you too.

Share:
43,300
Hudson
Author by

Hudson

Updated on September 26, 2020

Comments

  • Hudson
    Hudson over 3 years

    Please somebody help me fix this issue.

    Umbraco application as parent on IIS6 has the following version of System.Web.WebPages.Razor.

      <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      </sectionGroup>
    
      <system.web.webPages.razor>
      <host factoryType="System.Web.WebPages.Razor.WebRazorHostFactory, System.Web.WebPages.Razor" />
      <pages pageBaseType="System.Web.WebPages.WebPage">
      <namespaces>
        <add namespace="Microsoft.Web.Helpers" />
        <add namespace="umbraco" />
        <add namespace="Examine" />
      </namespaces>
    </pages>
    

    Blog Engine application as virtual directory under the Umbraco application on IIS6 has the following version of System.Web.WebPages.Razor.

    <configSections>
    <remove name="system.web.webPages.razor" />
    </configSections>
    
    <assemblies>
    <add assembly="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </assemblies>
    
    <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31BF3856AD364E35" culture="neutral" />
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
    </dependentAssembly>
    

    Even after i added the dependentAssembly still nothing works for me, Am wasting more than a week on this issue, Please help.

  • Hudson
    Hudson about 10 years
    Thank you very much for your response friend, actual assembly version of System.Web.WebPages.Razor.dll which is in Umbraco's bin folder is 1.0.0.0 and the actual assembly version of System.Web.WebPages.Razor.dll which is in Blog Engine's bin folder is 2.0.0.0 Thanks,
  • ProNotion
    ProNotion about 10 years
    It's been a while since I worked on a project that has nested applications so I'm not 100% sure on how the inheritance works however it sounds like your BlogEngine app is only seeing the assemblies in the parent applications bin directory e.g. the one with the v1.0.0.0 assembly.
  • Hudson
    Hudson about 10 years
    Thanks Melvin, I sorted the issues which is exactly as you said causing because of assembly binding between Umbraco application and BlogEngine application.
  • Vikram Deshmukh
    Vikram Deshmukh almost 8 years
    Of all the answers mentioned here, this is the only one that worked for me. Thanks @Liakat