1) Create an image with 2.1.1 runtime
2) dotnet new Mvc. Update the project file to specify a version for the shared runtime. Specify an older runtime e.g. <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0" />
3) Run the app. Views would build and be served.
4) Edit a view while the app is running and refresh the browser.
The compilation produces an error:
qqbcsiev.hbu(50,67): error CS0433: The type 'UrlResolutionTagHelper' exists in both 'Microsoft.AspNetCore.Mvc.Razor, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' and 'Microsoft.AspNetCore.Mvc.Razor, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
qqbcsiev.hbu(214,58): error CS0433: The type 'RazorInjectAttribute' exists in both 'Microsoft.AspNetCore.Mvc.Razor, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' and 'Microsoft.AspNetCore.Mvc.Razor, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
The issue is two parts:
1) Roll forward does not affect the deps file. Consequently the deps file will continue to claim (rightfully) that the app was compiled against Microsoft.AspNetCore.Mvc.Razor 2.1.0.0 and compilation will attempt to use these.
2) A couple of runtime assemblies are added as ApplicationParts by default - https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc/MvcServiceCollectionExtensions.cs#L59-L72 - one of which is the Razor assembly that's causing the version conflict error above. They have the version of the runtime which in this case is 2.1.1.0 Interestingly, removing these assemblies as application parts gets views to compile correctly.
FYI @rynowak
@wdmeeste1 could you run dotnet --info in your project directory?
Is there a fix for this?
@pranavkm Is there a solution now?
@pranavkm
dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.1.301
Commit: 59524873d6
Runtime Environment:
OS Name: ubuntu
OS Version: 16.04
OS Platform: Linux
RID: ubuntu.16.04-x64
Base Path: /usr/share/dotnet/sdk/2.1.301/
Host (useful for support):
Version: 2.1.1
Commit: 6985b9f684
.NET Core SDKs installed:
1.0.0-preview2-1-003177 [/usr/share/dotnet/sdk]
1.1.0-preview1-005077 [/usr/share/dotnet/sdk]
1.1.5 [/usr/share/dotnet/sdk]
2.1.301 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 1.0.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
Updating all the Microsoft.* nuget packages from 2.1.0 to 2.1.1 seems to fix the problem:
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
We'll try and address this in the runtime. In the meantime, the fix is to ensure your app's compiling against the runtime it'll target. Like I mentioned in my earlier comment, this problem crops up because your app's compiling against an older version of the runtime, but running against a newer one. Making sure the two are in sync should fix this.
Here's what you would need to do to ensure that, some of which are re-iterations of https://docs.microsoft.com/en-us/aspnet/core/migration/20_21?view=aspnetcore-2.1#rules-for-projects-targeting-the-shared-runtime
1) You must reference the Microsoft.NET.Sdk.Web Sdk <Project Sdk="Microsoft.NET.Sdk.Web"> in your app
2) Remove version specifications for the Microsoft.AspNetCore.App \ Microsoft.AspNetCore.All from the package reference so that the Sdk dictates it: <PackageReference Include="Microsoft.AspNetCore.App" />
3) Ensure you have the 2.1.301 SDK and 2.1.1 runtime installed.
Solution it worked out!
I managed to solve this problem by giving a down update on my .csproject.
Version with bug
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0" />
NEW
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />
2.1.3 - https://github.com/aspnet/Mvc/pull/7989.
Fixed in dev via https://github.com/aspnet/Mvc/commit/042c833145b6bd15ae67820cdfac2990eff0d469.
Tracking release verification via https://github.com/aspnet/Release/issues/316
Still not working, having SDK version 2.1.400 with Runtime 2.1.2 installed ONLY and same exception occurs when trying to edit cshtml while debugging in VS Code.
This issue continues to occur for me, randomly, as I build my application on the command-line while Visual Studio 2017 is open.
SDK: 2.1.403
@BeePM \ @csharpfritz, could you file a new issue with a repro app? The original issue happened all the time with runtime compilation and I just verified it does not repro with the latest runtime.
Most helpful comment
We'll try and address this in the runtime. In the meantime, the fix is to ensure your app's compiling against the runtime it'll target. Like I mentioned in my earlier comment, this problem crops up because your app's compiling against an older version of the runtime, but running against a newer one. Making sure the two are in sync should fix this.
Here's what you would need to do to ensure that, some of which are re-iterations of https://docs.microsoft.com/en-us/aspnet/core/migration/20_21?view=aspnetcore-2.1#rules-for-projects-targeting-the-shared-runtime
1) You must reference the
Microsoft.NET.Sdk.WebSdk<Project Sdk="Microsoft.NET.Sdk.Web">in your app2) Remove version specifications for the
Microsoft.AspNetCore.App\Microsoft.AspNetCore.Allfrom the package reference so that the Sdk dictates it:<PackageReference Include="Microsoft.AspNetCore.App" />3) Ensure you have the 2.1.301 SDK and 2.1.1 runtime installed.