Nullables treated as non-nullable at runtime
See original GitHub issueMy model includes a DateTime?
property
public class CampaignDesignerRequest
{
//...
public DateTime? CampaignStartDate { get; set; }
//...
}
My view inherits the model
@inherits RazorEngineCore.RazorEngineTemplateBase<Fourstarzz.Accessors.ReportTemplates.Models.DesignedCampaign_RenderModel>
At write time, the intellisense recognizes CampaignStartDate as a nullable and shows an error hint if I try to run date string formatting without specifying .Value
Model.CampaignStartDate.Value.ToShortDateString()
However when I run the code, it gives me the error
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException : ‘System.DateTime’ does not contain a definition for ‘Value’
I’ve tested the same on other value types, like int and double, and get the same kind of error.
Versions
- RazoreEngineCore 2020.9.1
- .NET framework 4.8.
Any thoughts on potential causes?
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Can a non-nullable reference type in C# 8 be null in runtime?
Now that might seem like it's now cannot be null. But if we reference this class with another library that does not use...
Read more >Nullable reference types
Nullable reference types refers to a group of features enabled in a nullable aware context that minimize the likelihood that your code causes ......
Read more >Solution - Non-nullable Property Must Contain a Non-null ...
Non-nullable property must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
Read more >Nullable Reference types in C# – Best practices
In this tutorial, I look at the state of the Nullable Reference Types ... a NullReferenceException might be thrown at run time, for...
Read more >Embracing Non-Nullable Reference Types in C# 8
The Non-Nullable Reference Types are a new breaking-change coming in C# 8.0. ... variable with a null value to our method, and we're...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’d be happy to contribute documentation if we want to promote it from an issue to the wiki or readme
I’ll try to push some changes this week