Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.
/ csharp8-nrt-test Public archive

This is a test to highlight an issue when using C# 8.0's null-reference type feature as discussed in the StackOverflow question found here: https://stackoverflow.com/q/65692568/3034273

Notifications You must be signed in to change notification settings

Xerillio/csharp8-nrt-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The issue displayed in this repo

If you're developing an application where C# 8.0's null-reference type (NRT) feature enabled while using external libraries or references to other projects that have not been developed with this feature enabled, the compiler will not warn you about the use of objects returned from said libraries.

In the sample app here LegacyLibrary does not have NRT enabled and allows returning null from PersonFactory.CreatePerson if either the first or last name are null/whitespace or if the given age is below 0. Because NrtEnabledProject has NRT enabled, I would expect to get a warning if I try to dereference the return value from CreatePerson. The signature of the method GetUserInfo says it returns a non-nullable Person, however, because of using the factory from the LegacyLibrary this "promise" is broken and you will have a false trust in what GetUserInfo returns.

You can confirm this by entering an age of "-1" which will cause a null-reference exception to be thrown.

About

This is a test to highlight an issue when using C# 8.0's null-reference type feature as discussed in the StackOverflow question found here: https://stackoverflow.com/q/65692568/3034273

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages