Skip to content

CultureName "c" and "C" get mapped to Invariant Culture #114328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,23 @@ private static void Test(Span<char> span)
// When converting to AssemblyName, the culture name is lower-cased
// by the CultureInfo ctor that calls CultureData.GetCultureData
// which lowers the name for caching and normalization purposes.
Assert.Equal(fromTryParse.CultureName.ToLower(), fromParse.ToAssemblyName().CultureName);

string lowerCase = fromTryParse.CultureName.ToLower();
if (lowerCase != "c")
{
Assert.Equal(lowerCase, fromParse.ToAssemblyName().CultureName);
}
else
{
// Cultures "c" and "C" get mapped to Invariant Culture.
Assert.Equal("", fromParse.ToAssemblyName().CultureName);
Assert.Equal(CultureInfo.InvariantCulture, fromParse.ToAssemblyName().CultureInfo);
}
}
else
{
Assert.True(fromParse.ToAssemblyName().CultureName is null);
}


// AssemblyNameInfo.FullName can be different than AssemblyName.FullName:
// AssemblyNameInfo includes public key, AssemblyName only its Token.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Globalization;
using Xunit;

namespace System.Reflection.Metadata.Tests.Metadata
Expand Down Expand Up @@ -116,6 +117,19 @@ public void CultureNameGetLoweredByToAssemblyName()
Assert.Equal("aa", assemblyNameInfo.ToAssemblyName().CultureName);
}

[Theory]
// "c" is an invalid culture identifier in Full Framework
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
[InlineData('c')]
[InlineData('C')]
public void Culture_C_IsMappedToInvariantCulture(char culture)
{
AssemblyNameInfo assemblyNameInfo = AssemblyNameInfo.Parse($"name,culture={culture}".AsSpan());
Assert.Equal(culture.ToString(), assemblyNameInfo.CultureName);
Assert.Equal("", assemblyNameInfo.ToAssemblyName().CultureName);
Assert.Equal(CultureInfo.InvariantCulture, assemblyNameInfo.ToAssemblyName().CultureInfo);
}

static void Roundtrip(AssemblyName source)
{
AssemblyNameInfo parsed = AssemblyNameInfo.Parse(source.FullName.AsSpan());
Expand Down
Loading