1

I am trying to use FluentEmail 2.8.0 in an Azure Function. However, I had the following exception.

RazorLight.RazorLightException: Can't load metadata reference from the entry assembly. Make sure PreserveCompilationContext is set to true in *.csproj file

I have added the following into csproj

<PropertyGroup>
    <FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>

<PropertyGroup>
    <PreserveCompilationReferences>true</PreserveCompilationReferences>
    <PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>

But I still get the same error.

Anyone has come across this before?

Environment: .NET Core 3.1, Azure Functions v3

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sam
  • 640
  • 5
  • 15

1 Answers1

1

At least I am able to find a workaround.

  1. Do not use the razor renderer from fluent email factory

  2. Use the following

             var engine = new RazorLightEngineBuilder()
                         .UseEmbeddedResourcesProject(typeof(EmailService))
                         .UseMemoryCachingProvider()
                         .SetOperatingAssembly(Assembly.GetExecutingAssembly())
                         .Build();
             var result = engine.CompileRenderStringAsync(templateName, template, viewModel);
    

...

then use _fluentEmail.Create()...Body(result, true)

add the missing nuget package System.Threading.AccessControl also.

Sam
  • 640
  • 5
  • 15