While writing some code handling assemblies in C# I noticed inconsistencies in field values of Assembly object (example of System assembly):
> typeof(string).Assembly.FullName
"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
but when accessing CultureName field of AssemblyName object directly, its value is an empty string:
> typeof(string).Assembly.GetName().CultureName
""
When I run the same test on Linux (mono 3.99) I got another result:
> typeof(string).Assembly.GetName().CultureName
"neutral"
Why does .NET behaves that way? I couldn't find any information on msdn regarding default value of CultureName field in AssemblyName class or meaning of an
empty string. Does an empty string always refers to "neutral" culture name?
The CultureName property was introduced in .Net 4.5 and the value of that property for an Assembly with the neutral culture must be equal to an empty string like the name of the invariant culture because the CultureName uses theCultureInfo property (source):
public String CultureName
{
get
{
return (_CultureInfo == null) ? null : _CultureInfo.Name;
}
}
But in Mono the CultureName property has a different implementation (source). Why different? I think developers of Mono know the answer.
public string CultureName {
get {
if (cultureinfo == null)
return null;
if (cultureinfo.LCID == CultureInfo.InvariantCulture.LCID)
return "neutral";
return cultureinfo.Name;
}
}
So if you want to check that an AssemblyName has the neutral culture, use the code below:
if (object.Equals(assemblyName.CultureInfo, CultureInfo.InvariantCulture))
{ /* neutral culture */ }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With