Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] No 'refs' directory in published output results in error "Cannot find compilation library location for package 'Microsoft.Win32.Registry'" #2702

Closed
kichalla opened this issue Apr 19, 2017 · 3 comments

Comments

@kichalla
Copy link

Steps to reproduce

  • Install 2.0.0-preview1-005815 of CLI
  • md test
  • cd test
  • dotnet new webapi
  • dotnet publish
  • Run the app
    dotnet C:\test\bin\Debug\netcoreapp2.0\publish\test.dll
  • The above step works
  • Stop the server (Ctrl + C)
  • Open the published output folder and rename the refs directory to something else
  • Run the app again
    dotnet C:\test\bin\Debug\netcoreapp2.0\publish\test.dll

Note: The same scenario works fine with a CLI version like 005418

Expected behavior

Application runs fine

Actual behavior

Exception is thrown:

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()
   at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory)
   at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorReferenceManager.get_CompilationReferences()
   at Microsoft.Extensions.DependencyInjection.MvcRazorMvcCoreBuilderExtensions.<>c__DisplayClass5_0.<AddRazorViewEngineServices>b__1(IRazorEngineBuilder b)
   at Microsoft.AspNetCore.Razor.Language.RazorEngine.Create(Action`1 configure)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitClosedIEnumerable(ClosedIEnumerableCallSite closedIEnumerableCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.UseMvc(IApplicationBuilder app, Action`1 configureRoutes)
   at refsdirectoryrepro.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at refsdirectoryrepro.Program.Main(String[] args)

Environment data

.NET Command Line Tools (2.0.0-preview1-005815)

Product Information:
 Version:            2.0.0-preview1-005815
 Commit SHA-1 hash:  a150055dfb

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.15063
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Users\kichalla\AppData\Local\Microsoft\dotnet\sdk\2.0.0-preview1-005815\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0-preview1-002028-00
  Build    : 6d0caecf154d3398b9bc0e637089b6af9e250479

cc @mikeharder @pranavkm

@gkhanna79
Copy link
Member

@eerhardt Is this CLI or DependencyModel?

@kichalla
Copy link
Author

I filed this issue before we discussed with @eerhardt . We made some fixes at our end.

@eerhardt
Copy link
Member

This behavior is "by design".

When you have <PreserveCompilationContext>true</> in your .csproj, a refs folder is created on publish. If you are going to call, Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(), you need this folder in order to get your compilation libraries. If you move/delete the refs folder, the libraries can't be resolved, and the correct exception is thrown.

The consuming code either needs to not call ResolveReferencePaths, or you need to leave the refs folder in place.

The reason this used to work is because your development machine still has a NuGet cache on it. And there is resolution path logic that knows how to look in the NuGet cache. Even before our change, if you moved this app to a clean machine, it would still fail. It just so happened the NuGet cache exists on your dev machine.

With the latest fixes, the DependencyModel will only probe the locations that the host knows how to probe. Thus it will no longer check the NuGet cache, unless the host will also check the NuGet cache (which doesn't happen for published apps).

Closing as by design.

@msftgits msftgits transferred this issue from dotnet/core-setup Jan 30, 2020
@dotnet dotnet locked as resolved and limited conversation to collaborators Dec 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants