Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft.AspNetCore.Mvc.ViewFeatures version

I'm rather puzzled by the following error message I am finding in my logs on the IIS server since updating to asp core 2.1.3:

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
      An unhandled exception has occurred while executing the request.
Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred:
error CS1705: Assembly 'JC' with identity 'JC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' which has a higher version than referenced assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures' with identity 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CompileAndEmit(RazorCodeDocument codeDocument, String generatedCode)
   at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CompileAndEmit(String relativePath)
   at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.OnCacheMiss(String normalizedPath)

Firstly, because it only seems happen on certain pages - forms it seems, and second, because I'm not sure the appropriate way to fix it. I installed the latest hosting bundle to no avail https://github.com/dotnet/core/blob/master/release-notes/2.1/2.1.3/2.1.3.md

Should I manually replace the dll Microsoft.AspNetCore.Mvc.ViewFeatures in the refs folder in my app directory?

like image 742
Mikustykus Avatar asked Mar 06 '23 12:03

Mikustykus


2 Answers

You'll get this when one project references another and both have a dependency on the same NuGet package, but different versions thereof. Simply, the solution is to downgrade one or upgrade the other. Pick a version (you'll likely just want to use the highest, since there's not really any reason to use a lower version for something like ViewFeatures). Then, edit your project files and change the relevant PackageReference line to that version.

It's possible, you may not actually be depending directly on this particular package, but rather a meta package that includes it, such as Microsoft.AspNetCore.App. However, the same thing applies. Make sure the same version is being used by both projects of that meta package.

A final unfortunate possibility might be one project depending on a meta package while another is depending on the ViewFeatures package directly, and the version of one may not necessarily actually line up with the version of the other. In that case, you can view the meta package on nuget.org and see what version of the individual package is included with that there (it will be listed as a dependency of the meta package). The make sure your reference to the individual package matches.

Long and short, it may take a little footwork, but the idea is that you need to get both projects on the same version of this package if you want to reference one from the other.

like image 182
Chris Pratt Avatar answered Mar 10 '23 12:03

Chris Pratt


I think I have recently experienced the same issue, just different packages.

Like, @Chris Pratt answered, in short, I reckon you have 2 projects, JC, and RefersToJC. Meaning, the 2nd project has a dependency to JC. (Please help me confirm on this).

Both of them depends on Microsoft.AspNetCore.Mvc.ViewFeatures. However, JC did specify it wants the version 2.1.2.0. Whereas, the other RefersToJC requires version 2.1.1.0 or just did not specify any version at all.

Therefore, inside RefersToJC.SomeClass, a line JC.SomeClass.Something() will throw CS1705 error.

Solution: Open Manage Nuget packages... of your RefersToJC project and download Microsoft.AspNetCore.Mvc.ViewFeatures with the version of 2.1.2 (even though we have Microsoft.AspNetCore.App metapackage.)

Yes, somehow it messed up and fresh projects (not migrating from old versions) just work.

like image 41
Lam Le Avatar answered Mar 10 '23 12:03

Lam Le