With the release of .NET 5 it was finally time to try record types. Here is my first attempt that I copied from the documentation:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public record Product | |
{ | |
public string Name { get; init;} | |
public Teacher(string name) => Name = name; | |
} |
Unfortunately this turned out not the success I was hoping for. Visual Studio returned the following error message:
Severity | Code | Description | Project | File | Line | Suppression State |
Error | CS0518 | Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported | NHibernate.Tests | C:\NHibernate.Tests\Domain\Product.cs | 17 | Active |
The error is not very descriptive but the reason I got it because I forgot to update the project to .NET 5. The fix was easy; after updating the target framework the error disappeared:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<TargetFramework>net5.0</TargetFramework> |