Loading a view embedded within a class library on Azure causes an exception about missing compilation libraries packages in the System.*
or Microsoft.*
namespace.
Exception.
I've created a bare repo to reproduce the problem. I created an application and library through VS and did the minimum possible to get an embedded view into the library and display it in a partial on the home page. It should work fine if cloned and run within VS, but fail if deployed to Azure.
https://github.com/svallis/ClassViews
Partial rendered correctly.
Deployed to azure the test repo throws the following exception on the home page:
InvalidOperationException: Can not find compilation library location for package 'microsoft.codeanalysis.common'
Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()
Navigating to the /Home/About
page without an embedded partial works correctly.
On my full project I was receiving the same error but with a different package:
Can not find compilation library location for package 'system.data.sqlclient'
Is anybody able to provide any insight on this? I assumed it's more likely to find an answer here than going through Azure support, but happy to take any suggestions. The same code deployed to an MS provided docker container works perfectly, just as it does in development, so it seems like it's something in the way Azure is configured.
/cc @pranavkm
MvcRazorCompileOnPublish
disables publishing refs
assemblies meant for runtime compilation. The idea is that since your application has precompiled views, you wouldn't need the refs for runtime compilation. However, your embedded views require these. There's two ways to fix this
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
in your csproj. This should continue publishing the refs
directory as part of the publish output.That makes perfect sense @pranavkm - thanks very much for the explanation. I've gone with your former suggestion for now, I'm going to hold off on precompiling the views in the class library until it's a little more streamlined (I assume eventually it should be as easy as it is to enable on the application, just flip a bool in the csproj?)
Most helpful comment
MvcRazorCompileOnPublish
disables publishingrefs
assemblies meant for runtime compilation. The idea is that since your application has precompiled views, you wouldn't need the refs for runtime compilation. However, your embedded views require these. There's two ways to fix this<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
in your csproj. This should continue publishing therefs
directory as part of the publish output.