So it appears, that after updating my project to .NET 8.0, and updating all the NuGet packages to the latest available versions, email content generator I use stopped working. Exception that I get looks like this:
An unhandled exception has occurred while executing the request.
System.TypeLoadException: Type '<ExecuteAsync>d__0' from assembly 'hmc151k1.dzl, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' tried to override method 'MoveNext' but does not implement or inherit that method.
at RazorLight.CompiledTemplates.GeneratedTemplate.ExecuteAsync()
at RazorLight.TemplateRenderer.RenderPageCoreAsync(ITemplatePage page, PageContext context)
at RazorLight.TemplateRenderer.RenderPageAsync(ITemplatePage page, PageContext context, Boolean invokeViewStarts)
at RazorLight.TemplateRenderer.RenderAsync(ITemplatePage page)
at RazorLight.EngineHandler.RenderTemplateAsync[T](ITemplatePage templatePage, T model, TextWriter textWriter, ExpandoObject viewBag)
at RazorLight.EngineHandler.RenderTemplateAsync[T](ITemplatePage templatePage, T model, ExpandoObject viewBag)
at RazorLight.EngineHandler.CompileRenderAsync[T](String key, T model, ExpandoObject viewBag)
at API.Service.Email.Helpers.RazorParser.ParseAsync[T](String template, T model) in D:\Projects\Projekti\API\api\API.Service\Email\Helpers\RazorParser.cs:line 28
at API.Service.Email.Helpers.RazorParser.UsingTemplateFromEmbeddedAsync[T](String path, T model) in D:\Projects\Projekti\API\api\API.Service\Email\Helpers\RazorParser.cs:line 20
at API.Service.Email.EmailContentGenerator.GenerateAsync[T](T emailDataModel) in D:\Projects\Projekti\API\api\API.Service\Email\EmailContentGenerator.cs:line 51
at API.Service.Email.EmailDispatcher.Dispatch[T](String recipient, String subject, T emailDataModel) in D:\Projects\Projekti\API\api\API.Service\Email\EmailDispatcher.cs:line 22
at API.Service.Auth.GenerateLoginTokenHandler.Handle(GenerateLoginTokenCommand request, CancellationToken cancellationToken) in D:\Projects\Projekti\API\api\API.Service\Auth\GenerateLoginTokenHandler.cs:line 73
at API.Controllers.AuthController.GenerateLoginToken(LoginTokenGenerateViewModel loginViewModel) in D:\Projects\Projekti\API\api\API\Controllers\AuthController.cs:line 63
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
The part between from assembly and Version=0.0.0.0 changes every time this exception is raised.
RazorParser.cs is implemented like this:
public class RazorParser
{
private readonly Assembly assembly;
public RazorParser(Assembly assembly)
{
this.assembly = assembly;
}
public async Task<string> UsingTemplateFromEmbeddedAsync<T>(string path, T model)
{
var template = EmbeddedResourceHelper.GetResourceAsString(assembly, GenerateFileAssemblyPath(path, assembly));
return await ParseAsync(template, model);
}
async Task<string> ParseAsync<T>(string template, T model)
{
var project = new InMemoryRazorLightProject();
var engine = new RazorLightEngineBuilder().UseProject(project).Build();
return await engine.CompileRenderStringAsync<T>(Guid.NewGuid().ToString(), template, model);
}
string GenerateFileAssemblyPath(string template, Assembly fileAssembly)
{
string assemblyName = fileAssembly.GetName().Name;
return $"{assemblyName}.Email.{template}.{"cshtml"}";
}
}
Additionally, after updating the packages I have converted my project from having Program.cs and Startup.cs files to just having Program.cs file. But I have checked multiple times, and everything is moved from Startup.cs to Program.cs, nothing has been left behind.
Maybe someone has had a similar issue, and had already solved it?