#StackBounty: #c# #asp.net-mvc #razor FluentEmail.Razor Value cannot be null. Parameter name: operatingAssembly

Bounty: 50

I have an ASP.Net MVC application (targeted for .Net Framework 4.7.2).

I installed FluentEmail.Core, FluentEmail.Smtp and FluentEmail.Razor (all of them version 3.0.0)

FluentEmail.Razor required LightRazor version 2.0.0-rc3, I had to manually install it since nuget default settings will only download final release (at the time of posting this question, the final stable release of RazorLight is version 1.0.0 which does not meet the requirement of FluentEmail.Razor v 3.0.0).

In my code, I am sending emails with no issues like this:

public async Task<ActionResult> Index()
{

       var sender = new SmtpSender(() => new SmtpClient("localhost"));
       Email.DefaultSender = sender;


      var email = await Email
         .From("from-test@gmail.com")
         .To("to-test@gmail.com")
         .Subject("subject-test")
         .Body("body test")
         .SendAsync();           // this works perfectly

    return View();
}

Now when I try to use Razor, I get an error:

Value cannot be null.
Parameter name: operatingAssembly
ASP.Net MVC FluentEmail.Razor Error
Here is what I changed:

public async Task<ActionResult> Index()
{

    var sender = new SmtpSender(() => new SmtpClient("localhost"));
    Email.DefaultSender = sender;
    Email.DefaultRenderer = new RazorRenderer();    // this line causes the error
    
    var email = await Email
         .From("from-test@gmail.com")
         .To("to-test@gmail.com")
         .Subject("subject-test")
        .UsingTemplate("Dear @Model.FirstName this is a test", new { FirstName = "Mike" })
        .SendAsync();           
    
    return View();
}

I searched for answers to this question and found that I need to tell the RazorEngine soem information about the model typeof(dynamic) but I can’t do that, I have to specify a class name. So I created a dedicated class for the my model, but I cant pass a reference of RazorEngine to FluentEmail Default Renderer.

What am I doing wrong?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.