Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetOperatingAssembly makes CompileRenderAsync() to crash #196

Closed
olivierr91 opened this issue Jun 19, 2018 · 1 comment
Closed

SetOperatingAssembly makes CompileRenderAsync() to crash #196

olivierr91 opened this issue Jun 19, 2018 · 1 comment

Comments

@olivierr91
Copy link

olivierr91 commented Jun 19, 2018

My solution consist of 2 projects:

  • MyApp.Rest
  • MyApp.Core

Core uses Razor templating to generate emails and reports. Rest is a WebAPI only and references Core. Rest has the startup file, where RazorLight configuration takes place. Core contains the RazorViewRender, which in turns uses RazorLightEngine.

Using SetOperatingAssembly to an assembly of MyApp.Core (so resx files and other stuff are picked up correctly) results in a System.NullReferenceException

Startup.cs:

            services.AddRazorLight(() => {
                return new RazorLightEngineBuilder()
                      .SetOperatingAssembly(Assembly.GetAssembly(typeof(RazorViewRenderer)))
                      .UseFilesystemProject(AppContext.BaseDirectory)
                      .UseMemoryCachingProvider()
                      .Build();
            });

RazorViewRender.cs:

        public async Task<string> RenderAsync<TModel>(string name, TModel model) {
            return await _engine.CompileRenderAsync(name, model);
        }

Stack Trace:

"Object reference not set to an instance of an object."
   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)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at RazorLight.Compilation.TemplateFactoryProvider.<CompileAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at RazorLight.Compilation.TemplateFactoryProvider.<CreateFactoryAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at RazorLight.RazorLightEngine.<CompileTemplateAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at RazorLight.RazorLightEngine.<CompileRenderAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at SitkaWebApp.Server.Core.Services.Documents.RazorViewRenderer.<RenderAsync>d__2`1.MoveNext() in C:\Users\orobe\Documents\IT Services\Customers\000055 - SITKA\Web App\SitkaWebApp.Server.Core\Services\Documents\RazorViewRenderer.cs:line 13

@toddams
Copy link
Owner

toddams commented Jun 20, 2018

Issue is not created properly, must follow the template - https://github.com/toddams/RazorLight/issues/new?template=bug_report.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants