Skip to content

fix: warning as errror CS8669 on csharp generated file #204

@tomflenner

Description

@tomflenner

Description

When using the OpenFeature CLI code generator for C# in projects that have "warnings as errors" enabled, the generated code produces a compilation error.

Error

1>OpenFeature.g.cs(535,84): Error CS8669 :The annotation for Nullable reference types must only be used in code within a '#nullable' annotations context. Automatically generated code requires an explicit '#nullable' directive in the source.

Steps to Reproduce

  1. Create a C# project with <TreatWarningsAsErrors>true</TreatWarningsAsErrors> in the .csproj file
  2. Generate C# code using the OpenFeature CLI code generator
  3. Attempt to build the project
  4. Observe the CS8669 compilation error in the generated OpenFeature.g.cs file

Repro : https://github.com/tomflenner/openfeature-cli-sharp-repro

Expected Behavior

The generated code should compile without errors, even in projects with warnings as errors enabled.

Proposed Solution

Add #nullable enable directive at the top of the generated C# file (OpenFeature.g.cs). This will provide the explicit nullable context required by the compiler.

Image

Workaround

Used this rules in my .editorconfig :

[**/*.g.cs]
generated_code = true
# Disable nullable reference type warnings in generated code
dotnet_diagnostic.CS8669.severity = none

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions