Skip to content

CultureNotFoundException in Net6 but works in Net5 on same system #62929

@igandrews

Description

@igandrews

Description

We create some cultures to do string comparisons for our library. That requires access to alternate sort orders. Prior to .net 5 we were using new CultureInfo(0x30404). However with the change to ICU in .net 5 the culture that produced did not provide the same sort/compare results. We found that new CultureInfo("zh-TW-u-co-zhuyin") produced better results and so started using that in .net 5. However the same code on the same system but in .net 6 throws a CultureNotFoundException with a message of:

Culture is not supported. (Parameter 'name')
zh-TW-u-co-zhuyin is an invalid culture identifier.

In .net 5 the culture is found and created and the CultureInfo has an EnglishName 'Chinese (Taiwan, Sort Order=Zhuyin Sort Order)' and . Prior to .net 5 we try to use the lcid specified above but if it did hit this path it just creates an unknown culture (the EnglishName reads "Unknown Locale (zh-TW-u-co-zhuyin)"). So why is .net 5 able to load it and .net 6 is not?

Reproduction Steps

var c = new CultureInfo("zh-TW-u-co-zhuyin");

Expected behavior

This should construct the culture (with the correct CompareInfo) as it does in .net 5

Actual behavior

Culture is not supported. (Parameter 'name')
zh-TW-u-co-zhuyin is an invalid culture identifier.

Regression?

Yes this is a regression. In .Net 5 the culture is created. Prior to .net 5 an unknown culture with the default compareinfo is created but then we didn't use this then anyway - we used the 0x30404 as I mentioned above.

Known Workarounds

No response

Configuration

.NET 6 (6.00.21.52210)
Windows 10.0.19044

Other information

The exception is not thrown when the unicode extension tag is excluded but then it also doesn't actually sort correctly. In .net 5 sorting with the culture created as mentioned above and then comparing like the following would return -1:
c.CompareInfo.Compare("巴斯克語", "土耳其語")
But if I remove the -u unicode extension the culture created (whose EnglishName is then 'Chinese (Taiwan, CO_ZHUYIN)' in .net 5 and .net 6) would return 1 for the above. Please don't suggest "zh-TW_zhuyin" either. That too will construct a culture but not sort as desired.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions