RazorLight icon indicating copy to clipboard operation
RazorLight copied to clipboard

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

Open chinnarao opened this issue 7 years ago • 29 comments

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.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.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.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.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.d__8.MoveNext() in C:\Users\chinn\source\repos\one\Micro.Svc.Ad.Write.CreateAds\Services\CreateAdsService.cs:line 86

chinnarao avatar Jun 02 '19 09:06 chinnarao

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

smirnovp88 avatar Jun 04 '19 11:06 smirnovp88

Same here, I have tried to contact the developer. If someone can just let us know if this will be updated to handle .Net Core 3. I am willing to assist if I know this has a future and that someone else has not started on it already.

jacodv avatar Jul 15 '19 12:07 jacodv

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>

jacodv avatar Jul 20 '19 12:07 jacodv

@jacodv do you happen to have a fork w commits to actually see the differences more easily?

christophwille avatar Jul 31 '19 08:07 christophwille

@christophwille, I have a branch that I created from the cloned master. I tried to create a pull request without any success.

jacodv avatar Jul 31 '19 16:07 jacodv

You mean you cloned this repo? Well pushing wouldn't work unless you were a member of the team here. That's why I asked about your fork into your account.

christophwille avatar Jul 31 '19 16:07 christophwille

Nope, sorry. I cloned it. If I can get what I have into a fork, then I am willing to do it.

jacodv avatar Jul 31 '19 16:07 jacodv

Fork the repo into your own account (on GH), and then add a new remote origin locally using git. That then allows you to take the data from the clone to your fork.

christophwille avatar Jul 31 '19 16:07 christophwille

Cool, sounds like a plan. I will get to it in the morning. Thank you for the pointer...

jacodv avatar Jul 31 '19 16:07 jacodv

@christophwille: Excuse my ignorance. I have pushed to this branch on my fork (https://github.com/jacodv/RazorLight/tree/branch_jdevil-UpgradeToNetCore3) I hope you can access it.

jacodv avatar Jul 31 '19 16:07 jacodv

Yes, I can access it. To recap: updating the references + PreserveCompilationReferences is what did the trick in the end?

I see one issue here: 2.1 is the LTS, 2.2 goes out of support almost immediately when 3.0 ships. With those package changes it won't work for both 2.x and 3.0. (and PreserveCompilationReferences is ... strange)

christophwille avatar Jul 31 '19 17:07 christophwille

fyi, I took a page from https://github.com/toddams/RazorLight/issues/248#issuecomment-499436254 and tried that myself at https://github.com/christophwille/myhaflinger.com/commit/2d1292fd2170078b2168f452ff3bbde0119c5f5e - those two lines make it work (note I had MvcRazorCompileOnPublish previously, so you'll have to try if that is necessary too)

christophwille avatar Aug 01 '19 07:08 christophwille

@christophwille, just to be clear. You are using the current Nuget package 2.0.0-beta1 and you added the new project items and it worked?

jacodv avatar Aug 01 '19 07:08 jacodv

Yes, the plain package from NuGet with those changes to the csproj.

christophwille avatar Aug 01 '19 08:08 christophwille

Brilliant! Thank you.

jacodv avatar Aug 01 '19 08:08 jacodv

ref https://github.com/aspnet/AspNetCore/issues/7966

tai-yi avatar Aug 14 '19 06:08 tai-yi

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

kYann avatar Oct 03 '19 13:10 kYann

I experiment the same issue, has anyone solved this?

ssauriera avatar Oct 10 '19 08:10 ssauriera

After some testing I found a solution.

I add the followinf line in the *.csproj and works with 2.0.-beta1 version

<PreserveCompilationReferences>true</PreserveCompilationReferences>

Hope help some one

ssauriera avatar Oct 10 '19 12:10 ssauriera

@kYann a new RazorLight? Why?

This actualy repository is come to the die?

alexsandro-xpt avatar Nov 08 '19 20:11 alexsandro-xpt