Repository navigation
Fix null-string conversions to nullable C# extensible enums - #12576
Draft
Jorge Rangel (jorgerangel-msft) with Copilot wants to merge 2 commits into
Draft
Jorge Rangel (jorgerangel-msft) with Copilot wants to merge 2 commits into
Jorge Rangel (jorgerangel-msft) with Copilot wants to merge 2 commits into
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Open
4 tasks done
…num conversions Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix ArgumentNullException for nullable string extensible enum
Fix null-string conversions to nullable C# extensible enums
Nov 13, 2026
commit: |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the nullable extensible-enum conversion fix.
No open issues 🎉
What changed in this PR
Fixes #12572 in the C# client generator so converting a null string to a nullable extensible enum returns null instead of throwing.
Changes:
- Explicitly casts the conditional’s null branch to the nullable enum type.
- Adds regression tests using string variables with null, known, unknown, and empty values, while preserving exceptions for non-nullable conversions.
- Updates affected generation baselines and sample output.
| File | Description |
|---|---|
packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/ThingRequiredNullableLiteralString1.cs |
Applies nullable cast in generated fixture. |
packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/ThingOptionalLiteralString.cs |
Applies nullable cast in generated fixture. |
packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/StringExtensibleEnum.cs |
Updates enum exercised by regression tests. |
packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/PreviewExtensibleChoice.cs |
Applies nullable cast in generated fixture. |
packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/LegacyExtensibleChoice.cs |
Applies nullable cast in generated fixture. |
packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/DaysOfWeekExtensibleEnum.cs |
Applies nullable cast in generated fixture. |
packages/http-client-csharp/generator/TestProjects/Local.Tests/ExtensibleEnumTests.cs |
Tests nullable conversions and non-nullable rejection. |
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/EnumProviders/TestData/EnumProviderTests/BackCompat_ExtensibleEnumRemovedValueReadded.cs |
Updates restored-value baseline. |
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/EnumProviders/TestData/EnumProviderTests/BackCompat_ExtensibleEnumRemovedValueNotReaddedWhenProvidedByCustomCode.cs |
Updates custom-provided-value baseline. |
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/EnumProviders/TestData/EnumProviderTests/BackCompat_ExtensibleEnumRemovedValueNotReaddedWhenBaselineAccepts.cs |
Updates accepted-removal baseline. |
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/EnumProviders/TestData/EnumProviderTests/BackCompat_ExtensibleEnumNonPublicValueNotReadded.cs |
Updates non-public-value baseline. |
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/EnumProviders/TestData/EnumProviderTests/BackCompat_ExtensibleEnumCustomCodeTakesPrecedenceOverPreservedUnderscores.cs |
Updates customization-precedence baseline. |
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/ExtensibleEnumProvider.cs |
Generates explicitly typed nullable null branch. |
docs/samples/client/csharp/SampleService/SampleClient/src/Generated/Models/ThingRequiredNullableLiteralString1.cs |
Synchronizes sample with corrected conversion. |
docs/samples/client/csharp/SampleService/SampleClient/src/Generated/Models/ThingOptionalLiteralString.cs |
Synchronizes sample with corrected conversion. |
docs/samples/client/csharp/SampleService/SampleClient/src/Generated/Models/StringExtensibleEnum.cs |
Synchronizes sample with corrected conversion. |
docs/samples/client/csharp/SampleService/SampleClient/src/Generated/Models/DaysOfWeekExtensibleEnum.cs |
Synchronizes sample with corrected conversion. |
Review effort: Balanced
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Converting a null string to a nullable extensible enum throws because the conditional’s untyped
nullresolves through the non-nullable implicit operator. Existing null-literal tests bypassed the nullable operator and missed the failure.