无法加载文件或程序集&System; Web.Razor,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其中一个依赖项

时间:2016-10-05 17:07:50

标签: c# asp.net asp.net-mvc asp.net-mvc-4 razor

我的DNN网站工作正常,直到我添加一个新模块。一旦我在VS 2015 DNN中创建了一个新模块并将其添加到站点,就会出现此错误。

2016-10-05 12:37:38,851 [WIN-8EQ5384ADST][Thread:13][ERROR] DotNetNuke.Services.Exceptions.Exceptions - ~/Default.aspx?tabid=1216&error=An unexpected error has occurred&content=0
System.IO.FileLoadException: Could not load file or assembly 'System.Web.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)
File name: 'System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
   at System.Signature..ctor(IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
   at System.Reflection.RuntimeConstructorInfo.GetParametersNoCopy()
   at System.Reflection.RuntimeConstructorInfo.GetParameters()
   at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat)
   at System.Exception.GetStackTrace(Boolean needFileInfo)
   at LCE.DNN.Modules.StoreLocator.View.Page_Load(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

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].

在web.config模块中,我看到:

<configuration>
  <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-3.0.0.0" newVersion="3.0.0.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Razor" publicKeyToken="31BF3856AD364E35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
            </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebMatrix.Data" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

我在主web.config文件(网站配置文件)中看不到任何与System.Web.Razor相关的内容。

我是MVC和DNN的新手,有人可以指导我解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

看起来您尝试卸载,升级或安装各种ASP.NET组件,但发生了一些故障。列表中的重复项仅根据PublicKeyToken的大小写而有所不同,这可能表示您在尝试之间使用了不同版本的包或NuGets。

我会尝试以下方法来解决问题:

  • 备份所有内容。
  • 通过NuGet卸载所有软件包。留意错误。
  • 手动检查您的.csproj文件并删除NuGet可能未删除的任何引用
  • 重复packages.config个文件。
  • web.config删除所有dependentAssembly条目。
  • 将正确软件包的正确版本重新安装到正确的项目中。
  • 清除ASP.NET临时文件
  • 做一个干净的构建。

我之前已经看到过这种情况,对我来说,当我们的内部NuGet服务器出现某种问题时,它就会发生,尽管nuget.org也可能发生这种情况。

另一种可能性是你引用的references a version of Razor different from what you reference directly(我猜你的帖子中的DNN)。如果可能的话,您将不得不追捕那个并升级它,或以某种方式标准化单个版本。

无论如何,我仍然会做上述步骤。

答案 1 :(得分:0)

尝试在nuget控制台发出以下命令。

Install-Package Microsoft.AspNet.Razor -Version 2.0.30506

如果说它已安装,则运行:

Update-Package Microsoft.AspNet.Razor