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.

Update scaffolders to support nullable reference types

See original GitHub issue

Nullable reference types was a feature introduced in C# 8. In .NET 6 we intend to enable it for new projects by default (see dotnet/templating#3359).

Any code emitted into a project by scaffolders should ensure that it doesn’t introduce nullability warnings given the configuration of nullable reference types in the target project. This might mean updating the code to be “safe” for inclusion when nullable is on or off, or making the scaffolder emit different code depending on whether the project’s nullable context configuration (i.e. the value of the <Nullable> property in the .csproj file).

@vijayrkn

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:8
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
deepchoudherycommented, Oct 26, 2022

Hey @Rick-Anderson, all templates should be nullable friendly in .NET 7. There was a regression recently but should be resolved for GA.

0reactions
Rick-Andersoncommented, Oct 26, 2022

For Scaffolding the same templates are re-used for multiple TFM’s. So, the generated code is not nullable friendly for controllers, pages & identity. This is the current proposed plan of action:

Phase 1. The generated code from Scaffolding will add nullable disable at the page level to suppress the warning. Phase 2. Nullable enabled code will be scaffolded for all c# classes. Phase 3. Nullable enabled code will be scaffolded for Razor pages. Phase 4. Nullable enabled code will be scaffolded for Identity.

For .NET 7, I just needed to make the following change in 3 files

-  public Movie Movie { get; set; }
+ public Movie Movie { get; set; } = default!;

Can I get a guarantee this is fixed right for .NET 8? cc @vijayrkn @deepchoudhery

Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity Framework core6 Scaffold-DbContext for .NET 6 ...
I ran the Scaffold-DbContext command in the Package Manager Console ... "Warning CS8632 The annotation for nullable reference types should ...
Read more >
Update your codebase to use nullable reference types
Nullable reference types enable you to declare if variables of a reference type should or shouldn't be assigned a null value.
Read more >
Scaffolding (Reverse Engineering) - EF Core
The scaffolder can create EF model and entity types that use C# nullable reference types (NRTs). NRT usage is scaffolded automatically when NRT ......
Read more >
Preparing Entity Framework Core for Static Analysis and ...
In this article we walk through the process of updating an EF Core 3.1 based data ... FxCopAnalyzers) and C# 8's nullable reference...
Read more >
Techniques and tools to update your C# project - Migrating to ...
It may be of help when migrating to C# nullable reference types, as it will definitely uncover some cases where you need additional...
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