I'm using embedded files, latest beta1 version, on net461 full framework, migrating to netcore2.0 but in progress and need to work in both frameworks. Always getting error:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=RazorLight
StackTrace:
at RazorLight.Compilation.DefaultMetadataReferenceManager.Resolve(DependencyContext dependencyContext)
at RazorLight.Compilation.DefaultMetadataReferenceManager.Resolve(Assembly assembly)
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.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.Compilation.TemplateFactoryProvider.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.Compilation.TemplateFactoryProvider.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.RazorLightEngine.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at RazorLight.RazorLightEngine.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
I have the same issue. Have you found workaround by chance?
I didn't look deeply, I was hoping it was pretty obvious, because exception is thrown every time, and somebody will know it here, preferably creators :)
I'm going to investigate problem some time later, if nobody provides workaround or fix.
I found where the problem is. Problem is with DependencyContext.Load(assembly) it return null and exception is thrown in DefaultMetadataReferenceManager.Resolve method.
As I understand DependencyContext is only made to work with new csproj style project and for old csproj just return null. Here is one issue https://github.com/dotnet/cli/issues/3219
@toddams is the new RazorLight version made to work with only new csproj projects? If not then DefaultMetadataReferenceManager class need to work around this problem.
I totally forgot about full .NET while rewriting RL for 2.0 version. You may find correct implementation of reference manager in old commits, I used to handle it properly.
Can't fix it now as I'm far away from home, you can wait for the next week, or try to figure out the old code yourself :)
Good to hear that new RazorLight version should also work on old csproj projects.
I didn't look into old commits and I'm happy to wait for your return and fixes :)
Thanks.
You can check https://github.com/toddams/RazorLight/issues/147.
We solved a problem: (Check this fork)
https://github.com/glikoz/RazorLight
@glikoz Have you sent a PR for this?
Same issue!
@glikoz I tried your patch, but ran in some referencing issues.
"Method not found: System.Collections.Immutable.ImmutableArray`1
I'm using net471, maybe that explains it.
Humm, this looks like there is an assembly version issue possibly, have you checked which nuget packages you are referencing and binding redirects? It looks like at runtime you are getting an older / different version of the assembly containing MetadataReader. I'm running fine on net471.
@glikoz with your permission I'd like to send a PR, to see if we can get your solution, published in the nuget package.
Tracking this issue in #147
Sorry for late response @coinbull. Yes you can send pr, no problem