Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Razor runtime compilation produces errors if running on a shared runtime that's rolled forward #7969

Closed
pranavkm opened this issue Jun 25, 2018 · 13 comments
Assignees
Labels
3 - Done bug cost: S Will take up to 2 days to complete servicing-approved Shiproom has approved the issue
Milestone

Comments

@pranavkm
Copy link
Contributor

  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'
@pranavkm
Copy link
Contributor Author

pranavkm commented Jun 25, 2018

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.

@pranavkm
Copy link
Contributor Author

FYI @rynowak

@pranavkm
Copy link
Contributor Author

@wdmeeste1 could you run dotnet --info in your project directory?

@ChristianSauer
Copy link

Is there a fix for this?

@FrancisFYK
Copy link

@pranavkm Is there a solution now?

@wdmeest
Copy link

wdmeest commented Jun 27, 2018

@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

@wdmeest
Copy link

wdmeest commented Jun 27, 2018

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>

@pranavkm
Copy link
Contributor Author

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.

@srburton
Copy link

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" />

@pranavkm pranavkm self-assigned this Jun 29, 2018
@pranavkm pranavkm added bug 2 - Working cost: S Will take up to 2 days to complete labels Jun 29, 2018
@pranavkm pranavkm added this to the 2.2.0-preview1 milestone Jun 29, 2018
pranavkm added a commit that referenced this issue Jun 29, 2018
…ime that's rolled forward

Do not provide compilation references from runtime MVC assemblies. This avoids cases where the app is compiled
against an older MVC but running against a newer one (e.g. shared fx roll forward) resulting in compiling against multiple
versions of MVC assemblies

Fixes #7969
@pranavkm pranavkm modified the milestones: 2.2.0-preview1, 2.1.3 Jun 29, 2018
@pranavkm pranavkm added the servicing-consider Shiproom approval is required for the issue label Jun 29, 2018
pranavkm added a commit that referenced this issue Jun 29, 2018
…ime that's rolled forward

Do not provide compilation references from runtime MVC assemblies. This avoids cases where the app is compiled
against an older MVC but running against a newer one (e.g. shared fx roll forward) resulting in compiling against multiple
versions of MVC assemblies

Fixes #7969
@pranavkm
Copy link
Contributor Author

pranavkm commented Jun 29, 2018

2.1.3 - #7989.
Fixed in dev via 042c833.

Tracking release verification via https://github.com/aspnet/Release/issues/316

pranavkm added a commit that referenced this issue Jun 29, 2018
…ime that's rolled forward

Do not provide compilation references from runtime MVC assemblies. This avoids cases where the app is compiled
against an older MVC but running against a newer one (e.g. shared fx roll forward) resulting in compiling against multiple
versions of MVC assemblies

Fixes #7969
@BeePM
Copy link

BeePM commented Aug 27, 2018

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.

@csharpfritz
Copy link
Member

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

@pranavkm
Copy link
Contributor Author

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3 - Done bug cost: S Will take up to 2 days to complete servicing-approved Shiproom has approved the issue
Projects
None yet
Development

No branches or pull requests

7 participants