System.Runtime, Version=4.2.1.0, PublicKeyToken=b03f5f7f11d50a3a has a higher version than referenced assembly

风流意气都作罢 提交于 2020-05-13 04:25:48

问题


I upgraded my ASP.NET CORE application from sdk .NET Core 2.0 to .NET Core 2.1. I can run the solution in my localhost but when I deploy it to another server there is an exception. And the exception is below. The steps I have done to solve the issue so far are below and it throws the same error with all the modification that I did seems nothing works. Does anybody have any suggestion how to solve this issue?

Steps I've done:

  1. Modify the setting for the project

     <PropertyGroup>
        <TargetFramework>netcoreapp2.1</TargetFramework>
        <Platforms>AnyCPU;x64</Platforms>
        <RuntimeFrameworkVersion>2.1.0</RuntimeFrameworkVersion>
        <UseNETCoreGenerator>true</UseNETCoreGenerator>
        <RazorCompileOnBuild>true</RazorCompileOnBuild>
      </PropertyGroup>
    
  2. I also added binding redirect in the web.config

    assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"
    bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.1.0" 
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.1.0" />
      </dependentAssembly>
    </assemblyBinding>
    
  3. Install .net core 2.1 on the server

  4. I also deleted my .vs folder and close my visual studio and open it again.

Exception :

Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred:error CS1705: Assembly Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Runtime' with identity 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'


回答1:


I had same problem. When I added the Views folder from the solution to the publish folder then the problem went away. For some reason Razor requires these source files to be present in the server AND up-to-date even when it compiles them also into .dll. Therefore it is strange indeed that the Views folder is not automatically copied during publish.

I personally made a junction like this
junction "MyProject\bin\Release\netcoreapp2.1\linux-x64\publish\Views" "MyProject\Views"

Alternatively, disabling the following line might help (have not tested but this issue seems to be related since in earlier versions of Net.Core there was no Razor compilation).

<RazorCompileOnBuild>true</RazorCompileOnBuild>
to
<RazorCompileOnBuild>false</RazorCompileOnBuild>



来源:https://stackoverflow.com/questions/53402798/system-runtime-version-4-2-1-0-publickeytoken-b03f5f7f11d50a3a-has-a-higher-ve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!