NullReference
NullReference

Reputation: 1026

MVC Core fails to render CSHTML view from file

I have an self hosted application targeting .NET 4.6.1 and project targeting Microsoft.NET.Sdk.Web I have added AspNetCore 2.2.0 package and have all dependencies updated to the latest .NET 4.6.1 compatible packages. When trying to render an CSHTML view from file there is an exception thrown with following error

Assembly 'Microsoft.AspNetCore.Mvc.Razor' with identity 'Microsoft.AspNetCore.Mvc.Razor, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' uses 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Runtime' with identity 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

The precompiled views are working just fine. So i am not sure whats going on here, as i understand Microsoft.AspNetCore.Mvc.Razor requires an higher version of System.Runtime?

I have checked the nuget repo and it seems that i am using the latest version so i am not sure where to look from here :(

Any ideas ?

Upvotes: 0

Views: 180

Answers (2)

Panagiotis Kanavos
Panagiotis Kanavos

Reputation: 131237

The only solution is to upgrade to .NET Framework 4.7.2. .NET 4.6 is not compatible with .NET Standard 2.0 and the attempts to backport .NET Standard 2.0 support failed, generating a ton of bad binding redirects every time a package was added or upgraded.

This means that bad redirects will keep appearing, forcing you to remove them before every deployment, or find out they crept back after a failed deployment.

In the end, the .NET team admitted back porting .NET Standard 2.0 was a bad idea. The current compatibility matrix documentation explains that :

2 The versions listed here represent the rules that NuGet uses to determine whether a given .NET Standard library is applicable. While NuGet considers .NET Framework 4.6.1 as supporting .NET Standard 1.5 through 2.0, there are several issues with consuming .NET Standard libraries that were built for those versions from .NET Framework 4.6.1 projects.

For .NET Framework projects that need to use such libraries, we recommend that you upgrade the project to target .NET Framework 4.7.2 or higher.

There are no significant incompatibilities between 4.6 and 4.7.2 either, so targeting a fresh runtime (the latest is 4.8) isn't a blocking issue

Upvotes: 1

NullReference
NullReference

Reputation: 1026

The problem was related to wrong binding redirects.

Upvotes: 0

Related Questions