6
votes

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
Can cou specify the version of the System.Runtime package which should be used? Try to change it to 4.2.0.0Marvin Klar
Hi Marvin , Thank you for your response. I couldn't check it on VS Community, I tried to right click to see the version it doesn't show me anything. I saw it's listed under .net core 2.1. I also modify the of System Run time version to 4.2.0.0 in CurrentApplication.deps.json. It still throw the same exception.user10358804
"I can run the solution in my localhost but when I deploy it to another server there is an exception." How did you publish? Self-contained or framework dependent? On the second server, what prerequisites have you installed? Such is critical information which is currently missing.Lex Li
Hi Lex Li, i publish it as self contain. I haven't solved this issue. But my other coworker tried to publish from her machine to the server and it work. we have the same credential and code.user10358804

1 Answers

0
votes

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>