lukencode / FluentEmail

All in one email sender for .NET. Supports popular senders (SendGrid, MailGun, etc) and Razor templates.
https://lukelowrey.com/dotnet-email-guide-2021/
MIT License
3.04k stars 438 forks source link

ReplaceRenderer may throw NullReferenceException #285

Open pbolduc opened 3 years ago

pbolduc commented 3 years ago

We were testing some template rendering and were getting a NullReferenceException when this code is executing. I believe one of the model properties is null. I would think ReplaceRenderer should ether skip null properties or throw a custom exception representing this error.

https://github.com/lukencode/FluentEmail/blob/a94b1f3d084476dfeaeedd1845cdecd2b6718dbc/src/FluentEmail.Core/Defaults/ReplaceRenderer.cs#L13

The problem is this part pi.GetValue(model, null).ToString() when the property is null. The ToString() function call causes the exception.