Repository navigation
[release/11.0] JsonNamingPolicyAttribute: Add missing PascalCase - #135325
Merged
Merged
Conversation
Support for Pascal Case was added in #124644. However, JsonNamingPolicyAttribute was missed, leading to an exception when doing something like this: ```csharp [JsonNamingPolicy(JsonKnownNamingPolicy.PascalCase)] public class TestClass { public int Property { get; init; } } ``` ``` System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'namingPolicy') at System.Text.Json.Serialization.JsonNamingPolicyAttribute.ResolveNamingPolicy(JsonKnownNamingPolicy namingPolicy) at System.Text.Json.Serialization.JsonNamingPolicyAttribute..ctor(JsonKnownNamingPolicy namingPolicy) at System.Reflection.CustomAttribute.<CreateCustomAttributeInstance>g____PInvoke|30_0(QCallModule __pModule_native, ObjectHandleOnStack __type_native, ObjectHandleOnStack __pCtor_native, IntPtr* __ppBlob_native, IntPtr __pEndBlob_native, Int32* __pcNamedArgs_native, ObjectHandleOnStack __instance_native) at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit) at System.Text.Json.Serialization.Metadata.FSharpCoreReflectionProxy.GetFSharpCoreAssembly(Type type) at System.Text.Json.Serialization.Metadata.FSharpCoreReflectionProxy.IsFSharpType(Type type) at System.Text.Json.Serialization.Converters.FSharpTypeConverterFactory.CanConvert(Type typeToConvert) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetBuiltInConverter(Type typeToConvert) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetConverterForType(Type typeToConvert, JsonSerializerOptions options, Boolean resolveJsonConverterAttribute) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type type, JsonSerializerOptions options) at System.Text.Json.Serialization.Metadata.JsonTypeInfoResolverChain.GetTypeInfo(Type type, JsonSerializerOptions options) at System.Text.Json.JsonSerializerOptions.GetTypeInfoNoCaching(Type type) at System.Text.Json.JsonSerializerOptions.CachingContext.CreateCacheEntry(Type type, CachingContext context) --- End of stack trace from previous location --- [...] ``` After adding that line, the attribute works as expected.
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-text-json |
tarekgh
approved these changes
Oct 7, 2026
Member
|
Approved over email |
Member
|
/ba-g No test failures, but ba is hung. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Backport of #135238 to release/11.0
/cc @eiriktsarpalis @compujuckel
Customer Impact
Fixes a customer reported issue where the newly introduced
JsonNamingPolicyAttributedid not include support for the newly introduced PascalCase naming policy.Regression
Testing
Added functional tests verifying the fix.
Risk
Low. Makes a targeted and straightfoward fix adding missing functionality.