Update
So it looks like this is replicateable in .NET 4.7.2 as well:https://dotnetfiddle.net/NI8H1n
Original
I have been having an issue with a DateTime? in a razor template in a netcoreapp3.1. The template is being run through:
Engine.Razor.RunCompile("templateName", "templateKey" model: model);
The model being passed consists of the property:
public DateTime? IssueDate { get; set; }
The razor line that is throwing a null ref error inside the template is:
<td>Issue date: @(result.IssueDate.HasValue ? result.IssueDate.Value.ToString("dd/MM/yyyy") : "")</td>
The error:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
So after some debugging, I found that if I change the problematic line in the template to:
<td>Issue date: @(result.IssueDate != null? result.IssueDate.ToString("dd/MM/yyyy") : "")</td>
Then we are good to go.
So the question I have is why doesn't the initial line work?