toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.51k stars 259 forks source link

Cannot find compilation library location for package 'Microsoft.AspNet.WebApi.Client' #252

Open loukikbhandari opened 5 years ago

loukikbhandari commented 5 years ago

Hello , I am getting this error while running docker container with Net core 2.2 project which has following code

string result = await engine.CompileRenderAsync("Header.cshtml", Resource.Header, headerModel);

Expected behavior Should compile and render html

Information (please complete the following information):

Error occurred: System.InvalidOperationException: Cannot find compilation library location for package 'Microsoft.AspNet.WebApi.Client'\\n at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver resolver, List1 assemblies)\\\\n at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()\\\\n at System.Linq.Enumerable.SelectManySingleSelectorIterator2.MoveNext()\\n at RazorLight.Compilation.DefaultMetadataReferenceManager.Resolve(DependencyContext dependencyContext)\\n at RazorLight.Compilation.RoslynCompilationService.EnsureOptions()\\n at RazorLight.Compilation.RoslynCompilationService.get_ParseOptions()\\n at RazorLight.Compilation.RoslynCompilationService.CreateSyntaxTree(SourceText sourceText)\\n at RazorLight.Compilation.RoslynCompilationService.CreateCompilation(String compilationContent, String assemblyName)\\n at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(IGeneratedRazorTemplate razorTemplate)\\n at RazorLight.Compilation.RoslynCompilationService.CompileAsync(IGeneratedRazorTemplate razorTemplate)\\n--- End of stack trace from previous location where exception was thrown ---\\n at RazorLight.Compilation.TemplateFactoryProvider.CompileAsync(IGeneratedRazorTemplate razorTemplate)\\n at RazorLight.Compilation.TemplateFactoryProvider.CreateFactoryAsync(String templateKey)\\n at RazorLight.RazorLightEngine.CompileTemplateAsync(String key)\\n at RazorLight.RazorLightEngine.CompileRenderAsync(String key, Object model, Type modelType, ExpandoObject viewBag)\\n at

loukikbhandari commented 5 years ago

@toddams Have you came across this issue with docker containers having net core apps

pereirazc commented 5 years ago

@loukikbhandari I've found that workaround https://github.com/toddams/RazorLight/issues/217#issuecomment-428539715

SirMrDexter commented 5 years ago

@loukikbhandari is your publish profile set to self contained or framework dependent. I am deploying to a windows machine, with SelfContained as true in publish profile and have this issue as well. So I have a feeling its related to that.

SyntaxErrorOnLine1 commented 4 years ago

@SirMrDexter I wanted to add another data point, as I'm having this issue with SelfContained = false in my publish profile. So not sure that is the issue.

jzabroski commented 4 years ago

@SyntaxErrorOnLine1 Are you using a docker container? I just updated the FAQ with a bunch of information.

jzabroski commented 4 years ago

As a request, I wish people who ARE running in a container please upload to GitHub a sample project with the Dockerfile. It should lead to 100% reproducible problem.

SyntaxErrorOnLine1 commented 4 years ago

@jzabroski No, I'm not. I've just resolved my issue (I think - it's still to be fully tested) by setting MvcRazorCompileOnPublish = true in my project file, so it's likely that it's a different issue to the OP, but was giving the same error message. Sorry for the false positive.

mcrio commented 4 years ago

I can confirm exactly the same problem with .net core 2.2. It was resolved by applying the instructions from the FAQ. Thanks.

jzabroski commented 4 years ago

336 might be related.

@mcrio thanks for your feedback.