Back to Stackexchange Redis

SER350: language version too low for generated code

docs/rules/SER350.md

3.1.131.3 KB
Original Source

SER350: language version too low for generated code

The [AsciiHash] source generator emits UTF-8 string literals ("..."u8), which are C# 11. The project using the attribute is set to an older language version, so rather than emitting code that cannot compile, the generator emitted nothing and reported this.

Fixing it

Raise the language version:

xml
<LangVersion>11</LangVersion>

The language version is not tied to the target framework, so an old TargetFramework is not a barrier: any .NET 7 or later SDK can compile C# 11 for netstandard2.0 or net472. Those TFMs just default lower (C# 7.3), which is how this is usually reached.

Why this is a warning

Unlike the other rules in this space, this one reports a real problem rather than a suggestion, and it cannot fire spuriously - the language version is known, and it is only checked when [AsciiHash] is actually used. The alternatives are both worse: emit anyway and put errors inside generated code you cannot edit, or emit nothing silently and surface it as an unexplained "partial method has no implementing declaration".

Suppressing

Suppressing leaves the partial members unimplemented, so the build will fail anyway with a less helpful message. Raise <LangVersion> instead, or stop using [AsciiHash] in that project.