Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scaffolders to support nullable reference types #1594

Open
Tracked by #3359
DamianEdwards opened this issue Jun 30, 2021 · 5 comments
Open
Tracked by #3359

Update scaffolders to support nullable reference types #1594

DamianEdwards opened this issue Jun 30, 2021 · 5 comments
Labels

Comments

@DamianEdwards
Copy link
Member

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

@vijayrkn
Copy link
Contributor

vijayrkn commented Nov 9, 2021

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.

@Concresent
Copy link

Hi an update.
The error appears before the step Install-Package Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore which makes it disappear but the document text doesn't mention the error directly or that it will be resolved with the above step. Thanks!

@saitrump
Copy link

@wadepickett Confirmed! The error is no more showing as before.

@vijayrkn vijayrkn removed this from the 6.0.x milestone Sep 20, 2022
@Rick-Anderson
Copy link
Contributor

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

@deepchoudhery
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants