question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nullables treated as non-nullable at runtime

See original GitHub issue

My 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:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
farlee2121commented, Oct 2, 2020

I’d be happy to contribute documentation if we want to promote it from an issue to the wiki or readme

0reactions
farlee2121commented, Oct 12, 2020

I’ll try to push some changes this week

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found