Null Warnings Re: Student, Course Create and Edit

Dean Everhart 1,496 Reputation points
2023-03-27T19:29:05.2133333+00:00

Working on the following Contoso University Tutorial...

https://learn.microsoft.com/en-us/aspnet/core/data/ef-mvc/crud?view=aspnetcore-6.0#update-the-edit-page

The code runs successfully but has some warnings...

User's image

User's image

Errors:

Warning (active) CS8602 Dereference of a possibly null reference.

Severity Code Description Project File Line Suppression State

Warning CS8620 Argument of type 'IIncludableQueryable<Student, ICollection<Enrollment>?>' cannot be used for parameter 'source' of type 'IIncludableQueryable<Student, IEnumerable<Enrollment>>' in 'IIncludableQueryable<Student, Course?> EntityFrameworkQueryableExtensions.ThenInclude<Student, Enrollment, Course?>(IIncludableQueryable<Student, IEnumerable<Enrollment>> source, Expression<Func<Enrollment, Course?>> navigationPropertyPath)' due to differences in the nullability of reference types. ContosoUniversity C:\Users\User1\Desktop_Tech\Net_Contoso University_ContosoUniversity\ContosoUniversity\Controllers\StudentController.cs 38 Active

Project on GitHub:

https://github.com/DeanEverhart/ContosoUniversity1

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,158 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,253 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Xinran Shen - MSFT 2,091 Reputation points
    2023-03-28T03:05:19.6333333+00:00

    Hi @Dean Everhart

    These messages are warnings instead of errors, Your code and work well with these warnings. Here is the explanation from Microsoft Document:

    • CS8602 - Dereference of a possibly null reference.
    • CS8620 - Argument cannot be used for parameter due to differences in the nullability of reference types.

    From descriptions you can see it is all about nullable in asp.net core, You can also refer to this Docs to learn more about Working with Nullable Reference Types.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Xinran Shen

    0 comments No comments