runtime: ASP.NET MVC fails with "Cannot find compilation library location for package 'Microsoft.Win32.Registry'" on Ubuntu

Steps to reproduce

  1. VM with clean Ubuntu 16.04
  2. Install dotnet-dev-1.0.1 to install dependencies (https://www.microsoft.com/net/core#linuxubuntu)
  3. wget https://dotnetcli.azureedge.net/dotnet/Sdk/2.0.0-preview1-005817/dotnet-dev-ubuntu-x64.2.0.0-preview1-005817.tar.gz
  4. mkdir dotnet-dev-ubuntu-x64.2.0.0-preview1-005817
  5. tar xf dotnet-dev-ubuntu-x64.2.0.0-preview1-005817.tar.gz -C dotnet-dev-ubuntu-x64.2.0.0-preview1-005817
  6. mkdir mvc
  7. cd mvc
  8. …/dotnet-dev-ubuntu-x64.2.0.0-preview1-005817/dotnet new mvc
  9. …/dotnet-dev-ubuntu-x64.2.0.0-preview1-005817/dotnet run

Exception

Unhandled Exception: System.InvalidOperationException: Cannot find compilation library location for package 'Microsoft.Win32.Registry'
   at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeatureProvider.PopulateFeature(IEnumerable`1 parts, MetadataReferenceFeature feature)
   at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature)
   at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorReferenceManager.GetCompilationReferences()

grep -r DependencyModel *

bin/Debug/netcoreapp2.0/mvc.deps.json:          "Microsoft.Extensions.DependencyModel": "2.0.0-preview1-002028",
bin/Debug/netcoreapp2.0/mvc.deps.json:      "Microsoft.Extensions.DependencyModel/2.0.0-preview1-002028": {
bin/Debug/netcoreapp2.0/mvc.deps.json:          "lib/netstandard1.6/Microsoft.Extensions.DependencyModel.dll": {}
bin/Debug/netcoreapp2.0/mvc.deps.json:          "lib/netstandard1.6/Microsoft.Extensions.DependencyModel.dll": {}
bin/Debug/netcoreapp2.0/mvc.deps.json:    "Microsoft.Extensions.DependencyModel/2.0.0-preview1-002028": {
obj/project.assets.json:          "Microsoft.Extensions.DependencyModel": "2.0.0-preview1-002028",
obj/project.assets.json:      "Microsoft.Extensions.DependencyModel/2.0.0-preview1-002028": {
obj/project.assets.json:          "lib/netstandard1.6/Microsoft.Extensions.DependencyModel.dll": {}
obj/project.assets.json:          "lib/netstandard1.6/Microsoft.Extensions.DependencyModel.dll": {}
obj/project.assets.json:    "Microsoft.Extensions.DependencyModel/2.0.0-preview1-002028": {
obj/project.assets.json:        "lib/net451/Microsoft.Extensions.DependencyModel.dll",
obj/project.assets.json:        "lib/netstandard1.3/Microsoft.Extensions.DependencyModel.dll",
obj/project.assets.json:        "lib/netstandard1.6/Microsoft.Extensions.DependencyModel.dll",
obj/project.assets.json:        "build/Microsoft.Extensions.DependencyModel.dll",
obj/project.assets.json:        "build/desktop/Microsoft.Extensions.DependencyModel.dll",

https://github.com/dotnet/core-setup/pull/2039 was thought to fix this, but MVC still fails after this change.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 22 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I figured out what was causing my problem. @colindekker maybe this will work for yours too.

In my case, it began with simply a misunderstanding of what was causing the error to be thrown. Turns out I was using the NToastNotify library which uses embedded views. @colindekker are you using any embedded views?

Based on https://github.com/aspnet/Mvc/issues/6021#issuecomment-290745919,

I added <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish> to my .csproj and it ran just fine.

Here’s my new working .csproj,

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
    <PackageReference Include="NToastNotify" Version="3.0.2" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
  </ItemGroup>
</Project>

Hi, I’m receiving this error when I try to deploy to Azure. I’m referencing the stable build .NET Core 2.0 SDK, I think. I had no problems running it locally, but now this error is getting thrown on Azure. I don’t know why this is happening or how to fix it. Can anyone help?

PS, the above csproj also does not work without the following. PPS: I’m making a copy without any keys or passwords etc. anywhere to link here as a reference. of the project.

<PreserveCompilationContext>true</PreserveCompilationContext> <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>

@eerhardt / @mikeharder I’m seeing the same error (‘Cannot find compilation library location for package <package-name>’) with a barebones MVC under Windows, when I reference a DLL file in the web app. Do you think that is addressed by the fix as well? Note that the DLL is just a file, not a NuGet package, and by the error text it sounds like something is trying to treat it as a package. It seems that it happens for an MVC web app (not an Empty one), when targeting netcoreapp2.0 or net461.

EDIT: same results using dotnet run with the SDK/CLI latest bits (2.1.0-preview1-006984),