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

Cannot find compilation library location for package 'Microsoft.Win32.Registry' #1156

Closed
agriffard opened this issue Oct 31, 2017 · 13 comments · Fixed by #2005
Closed

Cannot find compilation library location for package 'Microsoft.Win32.Registry' #1156

agriffard opened this issue Oct 31, 2017 · 13 comments · Fixed by #2005
Milestone

Comments

@agriffard
Copy link
Member

I published an OC application on a server and hosted it on IIS and I had this error:
Cannot find compilation library location for package 'Microsoft.Win32.Registry'

I don't know what is the exact reason but I managed to fix it by adding this in my .csproj :
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>

See https://github.com/dotnet/core-setup/issues/2113 for more explanations

@sebastienros
Copy link
Member

I know an expert about these kind of things, he lives in France near Valence ...

@sebastienros sebastienros added this to the beta milestone Oct 31, 2017
@agriffard
Copy link
Member Author

I just figured out that OrchardCore.Cms.Web.csproj has these options:

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
    <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
  </PropertyGroup>

@jtkech
Copy link
Member

jtkech commented Oct 31, 2017

Yes, we precompile views so when publishing we don't need to output compile time assemblies in the refs subfolder.

@agriffard
Copy link
Member Author

Needs documentation to explain which properties to add in .csproj when you use OC.Targets nuget package or else it won't work when it is deployed on IIS.

@agriffard agriffard reopened this Dec 10, 2017
@jtkech
Copy link
Member

jtkech commented Dec 14, 2017

As a reminder.

  • If we don't use the razor precompilation tool we just need PreserveCompilationContext = true.

  • If we use the razor precompilation tool and we also use liquid tag helpers, we still need PreserveCompilationContext = true and we need MvcRazorExcludeRefAssembliesFromPublish = false.

  • If we use the razor precompilation tool and we don't use liquid tag helpers, we can use PreserveCompilationContext = false without defining MvcRazorExcludeRefAssembliesFromPublish (true by default).

@sebastienros sebastienros modified the milestones: beta, beta2 Dec 14, 2017
@rbflow
Copy link

rbflow commented Jan 30, 2018

I set this up

<PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish> 
  
 <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
</PropertyGroup>

however still throws the same error. I'm currently on VS 2017 15.5.5

@agriffard
Copy link
Member Author

agriffard commented Jun 2, 2018

This will be included inthe csproj when you create a Cms.Web application using the dotnet new template
for OC:

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

@jtkech
Copy link
Member

jtkech commented Jun 18, 2018

  • Just tried it works on my machine without the last line so that no refs folder is generated on publishing. Normally we don't need it because views are now precompiled and embedded in each module assembly on building by using the Sdk.Razor. And we fixed the "issue" where razor compilation was still triggered.

  • If there are views defined at the app level, they are precompiled by the old tool on publishing. But normally here also we don't need the refs folder.

  • That said, for a given module / theme using Sdk.Razor, for the precompilation to be effective, right now (with this sdk version) the module / theme needs to reference the .AspNetCore.Mvc package directly in its csproj file. If you forget this, views will not be precompiled, only embedded. In this case the razor compilation is done at runtime and needs compilation assemblies in the refs folder.

So, maybe better to re-add this line in the OC.Cms.Web application project file. On another side you will not see that some views of some modules are not precompiled.

<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>

@jtkech
Copy link
Member

jtkech commented Jun 18, 2018

Hmm, maybe something to add to the documentation

A module needs to use the razor sdk to have its razor views precompiled.

<Project Sdk="Microsoft.NET.Sdk.Razor">

But, for the precompilation to be effective you also need in each module project file.

<PackageReference Include="Microsoft.AspNetCore.Mvc" />

@agriffard
Copy link
Member Author

Thank you for the explanations @jtkech .

I migrated my OC website to the latest version and I was wondering what to change:
<TargetFramework>netcoreapp2.1</TargetFramework>

and then which package use:
Microsoft.AspNetCore.All (that is what I do currently) or Microsoft.AspNetCore.App (like in OrchardCore.Cms.Web)

@jtkech
Copy link
Member

jtkech commented Jun 18, 2018

As it is in the current OC.Cms.Web application.

And if you want all your modules views to be precompiled, don't forget to add to each module a direct reference to Microsoft.AspNetCore.Mvc.

Otherwise you will have razor compilation at runtime and then you will need the refs folder, and then you will need to re-introduce this line in your app project file.

<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>

@jtkech
Copy link
Member

jtkech commented Jun 19, 2018

@agriffard for infos

So, i'm working on a PR that will be ready for tomorrow

  • We will use the same Sdk.Razor (inherited by Sdk.Web) to precompile views defined at the application level, as we do for modules / themes views. So you will have to remove this line.

    <MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
    
  • Then, because each modules should precompile its views, it should reference AspnetCore.Mvc directly because it is a requirement. So, @sebastienros said to me to not re-introduce.

    <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
    

So at this point it will just be by default.

<PropertyGroup>
  <TargetFramework>netcoreapp2.1</TargetFramework>
  <TieredCompilation>true</TieredCompilation>
  <PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>

peterkeating added a commit to moov2/website-core that referenced this issue Oct 29, 2018
Following suggestions from various links (couple displayed below)

- toddams/RazorLight#203
- OrchardCMS/OrchardCore#1156
@kazinad
Copy link

kazinad commented Mar 5, 2019

I tried all the above advices, but I still got the following error:

System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) at System.Runtime.Loader.AssemblyLoadContext.LoadFromStream(IntPtr ptrNativeAssemblyLoadContext, IntPtr ptrAssemblyArray, Int32 iAssemblyArrayLen, IntPtr ptrSymbols, Int32 iSymbolArrayLen, ObjectHandleOnStack retAssembly) at System.Runtime.Loader.AssemblyLoadContext.LoadFromStream(Stream assembly, Stream assemblySymbols) at System.Reflection.Assembly.Load(Byte[] rawAssembly, Byte[] rawSymbolStore) at Microsoft.AspNetCore.Mvc.Razor.Internal.SharedRazorViewCompiler.CompileAndEmit(RazorCodeDocument codeDocument, String generatedCode) in C:\projects\orchard2\src\OrchardCore\OrchardCore.Mvc.Core\SharedRazorViewCompiler.cs:line 395 at Microsoft.AspNetCore.Mvc.Razor.Internal.SharedRazorViewCompiler.CompileAndEmit(String relativePath) in C:\projects\orchard2\src\OrchardCore\OrchardCore.Mvc.Core\SharedRazorViewCompiler.cs:line 353 at Microsoft.AspNetCore.Mvc.Razor.Internal.SharedRazorViewCompiler.OnCacheMiss(String normalizedPath) in C:\projects\orchard2\src\OrchardCore\OrchardCore.Mvc.Core\SharedRazorViewCompiler.cs:line 212 --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorPageFactoryProvider.CreateFactory(String relativePath) at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.CreateCacheResult(HashSet``1 expirationTokens, String relativePath, Boolean isMainPage) at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.OnCacheMiss(ViewLocationExpanderContext expanderContext, ViewLocationCacheKey cacheKey) at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.LocatePageFromViewLocations(ActionContext actionContext, String pageName, Boolean isMainPage) at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.FindView(ActionContext context, String viewName, Boolean isMainPage) at Microsoft.AspNetCore.Mvc.ViewEngines.CompositeViewEngine.FindView(ActionContext context, String viewName, Boolean isMainPage) at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.FindView(ActionContext actionContext, ViewResult viewResult) at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result) at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync() at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext) at OrchardCore.Modules.ModularTenantRouterMiddleware.Invoke(HttpContext httpContext) in C:\projects\orchard2\src\OrchardCore\OrchardCore.Modules\ModularTenantRouterMiddleware.cs:line 82 at OrchardCore.Modules.ModularTenantContainerMiddleware.Invoke(HttpContext httpContext) in C:\projects\orchard2\src\OrchardCore\OrchardCore.Modules\ModularTenantContainerMiddleware.cs:line 89 at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

This is my csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TieredCompilation>true</TieredCompilation>
<PreserveCompilationContext>true</PreserveCompilationContext>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="OrchardCore.Application.Cms.Targets" Version="1.0.0-beta2-69590" />
</ItemGroup>

</Project>

I ran out of ideas

peterkeating added a commit to EtchUK/Etch.OrchardCore.SiteBoilerplate that referenced this issue Mar 23, 2019
When running an Orchard Core instance within an Azure environment, when
a custom theme is enabled an exception prevents the front end from being
accessible. Below is a snipprt of the logged exception.

```
System.InvalidOperationException: Cannot find compilation library location for package 'Microsoft.NETCore.App'
```

To fix this issue (discussed here - OrchardCMS/OrchardCore#1156)
a couple of properties need to be added to the csproj for the main site
project.
peterkeating added a commit to EtchUK/Etch.OrchardCore.SiteBoilerplate that referenced this issue Mar 23, 2019
When running an Orchard Core instance within an Azure environment, when
a custom theme is enabled an exception prevents the front end from being
accessible. Below is a snipprt of the logged exception.

```
System.InvalidOperationException: Cannot find compilation library location for package 'Microsoft.NETCore.App'
```

To fix this issue (discussed here - OrchardCMS/OrchardCore#1156)
a couple of properties need to be added to the csproj for the main site
project.

Fixes #3.
mobinzk pushed a commit to EtchUK/Etch.OrchardCore.SiteBoilerplate that referenced this issue Apr 16, 2019
When running an Orchard Core instance within an Azure environment, when
a custom theme is enabled an exception prevents the front end from being
accessible. Below is a snipprt of the logged exception.

```
System.InvalidOperationException: Cannot find compilation library location for package 'Microsoft.NETCore.App'
```

To fix this issue (discussed here - OrchardCMS/OrchardCore#1156)
a couple of properties need to be added to the csproj for the main site
project.

Fixes #3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants