toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.51k stars 260 forks source link

Feature Nullable Reference Types not available #324

Closed klemmchr closed 4 years ago

klemmchr commented 4 years ago

Describe the bug When compiling a template I get the following errors

RazorLight.Compilation.TemplateCompilationException: Failed to compile generated Razor template:
- (11:1) Das Feature "Nullable-Verweistypen" ist in C# 7.3 nicht verfügbar. Verwenden Sie Sprachversion 8.0 oder höher.
- (17:1) Das Feature "Nullable-Verweistypen" ist in C# 7.3 nicht verfügbar. Verwenden Sie Sprachversion 8.0 oder höher.
- (24:1) Das Feature "Nullable-Verweistypen" ist in C# 7.3 nicht verfügbar. Verwenden Sie Sprachversion 8.0 oder höher.
- (30:1) Das Feature "Nullable-Verweistypen" ist in C# 7.3 nicht verfügbar. Verwenden Sie Sprachversion 8.0 oder höher.
- (32:1) Das Feature "Nullable-Verweistypen" ist in C# 7.3 nicht verfügbar. Verwenden Sie Sprachversion 8.0 oder höher.
- (38:1) Das Feature "Nullable-Verweistypen" ist in C# 7.3 nicht verfügbar. Verwenden Sie Sprachversion 8.0 oder höher.

Which translates to The feature "Nullable reference type" is not available in C# 7.3. Use Version 8.0 or higher. I'm not using nullable reference types anywhere in my model or template. My template isn't even 38 lines long.

To Reproduce

Expected behavior The template compiles without errors.

Information (please complete the following information):

hwinkelmann commented 4 years ago

What helped in my case was to explicitly switch to C# 8 by adding <LangVersion>8.0</LangVersion> to some PropertyGroup in the .csproj files. Hope this helps!

klemmchr commented 4 years ago

I'm targeting netcoreapp3.1 and have set LangVersion to latest so I have C# 8 available. Does it make a difference when I specify 8.0 explicitly?

jzabroski commented 4 years ago

@chris579 latest depends on your SDK, not your targeting pack.

klemmchr commented 4 years ago

In this case it would be worth mentioning this somewhere in the FAQ in the README. Seems to be a pitfall users might run into.

jzabroski commented 4 years ago

@chris579 Please submit a PR for what you have in mind and I'll review it.

dariel312 commented 4 years ago

@jzabroski Thanks for this solution, I was also having this problem and spent like 3 hours trying to fix it and was literally about to submit an issue before GitHub referred me to this issue.