RazorLight: .net core 3.0 + asp.net web api - code compiled but run time Error came

System.InvalidOperationException HResult=0x80131509 Message=Cannot find reference assembly ‘Microsoft.AspNetCore.Antiforgery.dll’ file for package Microsoft.AspNetCore.Antiforgery Source=Microsoft.Extensions.DependencyModel StackTrace: at Microsoft.Extensions.DependencyModel.Resolution.ReferenceAssemblyPathResolver.TryResolveAssemblyPaths(CompilationLibrary library, List1 assemblies) at Microsoft.Extensions.DependencyModel.Resolution.CompositeCompilationAssemblyResolver.TryResolveAssemblyPaths(CompilationLibrary library, List1 assemblies) at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver resolver, List1 assemblies) at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths() at System.Linq.Enumerable.SelectManySingleSelectorIterator2.MoveNext() at RazorLight.Compilation.DefaultMetadataReferenceManager.Resolve(DependencyContext dependencyContext) at RazorLight.Compilation.RoslynCompilationService.EnsureOptions() at RazorLight.Compilation.RoslynCompilationService.get_ParseOptions() at RazorLight.Compilation.RoslynCompilationService.CreateSyntaxTree(SourceText sourceText) at RazorLight.Compilation.RoslynCompilationService.CreateCompilation(String compilationContent, String assemblyName) at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(IGeneratedRazorTemplate razorTemplate) at RazorLight.Compilation.RoslynCompilationService.CompileAsync(IGeneratedRazorTemplate razorTemplate) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at RazorLight.Compilation.TemplateFactoryProvider.<CompileAsync>d__10.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at RazorLight.Compilation.TemplateFactoryProvider.<CreateFactoryAsync>d__8.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at RazorLight.RazorLightEngine.<CompileTemplateAsync>d__14.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at RazorLight.RazorLightEngine.<CompileRenderAsync>d__11.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Micro.Svc.Ad.Write.CreateAds.Services.CreateAdsService.<HtmlTemplate>d__8.MoveNext() in C:\Users\chinn\source\repos\one\Micro.Svc.Ad.Write.CreateAds\Services\CreateAdsService.cs:line 86

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 29

Commits related to this issue

Most upvoted comments

Attention: @toddams @smirnovp88 @chinnarao

I finally have a working solution upgraded to netcoreapp3. The solution has 3 new projects as well as a sample Postman collection under the samples directory.

There are a number of compiler warning and references to obsolete methods. I have not tried to fix those. If this code is accepted as a possible solution by @toddams then I will continue to help with the conversion of the code.

RazorLight.zip

Please let me know what you think…

The one change I had to make in my consuming WebAPI project that might not be obvious from the source. <PreserveCompilationReferences>true</PreserveCompilationReferences>

I have same issue. Installed Microsoft.AspNetCore.Antiforgery package and get error Cannot find reference assembly ‘Microsoft.AspNetCore.Antiforgery.dll’ file for package Microsoft.AspNetCore.Antiforgery.Reference. Any help appreciated. Thanks

I’ve created a RazorLight version for .NetCore 3.0 https://www.nuget.org/packages/RazorLight.NetCore3/ from https://github.com/whyseco/RazorLight