Home Dashboard Directory Help
Search

Error in LINQ OrderBy and FindAll methods when using Danish culture (da-DK). by MortenK


Status: 

Closed
 as By Design Help for as By Design


1
0
Sign in
to vote
Type: Bug
ID: 771650
Opened: 11/19/2012 2:05:25 PM
Access Restriction: Public
1
Workaround(s)
view
0
User(s) can reproduce this bug

Description

When using FindAll and OrderBy LINQ statements on a generic list<string> using Danish culture, errors in the expected output occurs. OrderBy sorts wrongfully (i.e. Not alphabetical), and FindAll.StartsWith doesn't actually find all strings that start with the specified string.

Both problems can be resolved by passing StringComparer.InvariantCultureIgnoreCase to the FindAll / OrderBy methods.
Details
Sign in to post a comment.
Posted by MortenK on 2/21/2013 at 11:15 AM
Hi Immo,

Thanks for the reply. As I mentioned in one of my other comments, I am now aware the sorting mechanism works like that, so OrderBy and FindAll are indeed fine. The real problem, faulty sorting, is still there though. It is not as first assumed in the OrderBy / FindAll methods: It is a problem in the culture configuration instead.

The culture considers double aa to be the same as the character å. However that is wrong, the double aa was removed from the language all the way back in 1948.

I understand that there might be differing opinions on this, and in any case it is certainly not an issue for the .NET framework team, but rather the culture team (if such exists).

Best,
Morten
Posted by Microsoft on 2/21/2013 at 7:40 AM
Thank you for your feedback. This issue is actually by-design.

This is not an issue with OrderBy or FindAll -- it is how the danish string comparsions work.

"a" is a char
"aa" is also a char but a different one which is why you get the strange looking behavior.

http://stackoverflow.com/questions/6535910/string-startwith-issue-with-danish-text

has some more information about some of this issue.

Regards,
Immo Landwerth
.NET Framework team
Posted by MortenK on 12/21/2012 at 1:29 PM
After researching it, I understand that the reason for the problem is that the Danish culture sorting mechanism treats aa as the danish letter å, which is one of the last letters in the alphabet. Therefore "aab" will appear after "b".

However this is highly unintuitive since the aa spelling of the letter Å was removed from the Danish language in 1948: http://en.wikipedia.org/wiki/%C3%85 (origin section).

While this error is not an error in LINQ's sorting mechanism as first assumed, it is still an error, but in the culture configuration instead, and should really be fixed as the end-result is a wrongful sort order.
Posted by Microsoft on 11/22/2012 at 12:33 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Sorry for the first time not reproduced your issue.
Posted by MortenK on 11/20/2012 at 1:58 AM
That's pretty lazy guys, it's 3 lines of code you have to execute and check the output of. I already got the problem fixed by using the workaround, so this bug submission is just for your info.

I made the video: Here I start the BugDemo project in VS, run it, and show that that the output is wrong, by inspecting the objects after hitting a breakpoint.

http://screencast.com/t/Gcjsb9ci8
Posted by Microsoft on 11/19/2012 at 10:58 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. In order to efficiently investigate and reproduce this issue, we are requesting a video. Please submit this information to us within 3 business days. We look forward to hearing from you with this information.
Posted by Microsoft on 11/19/2012 at 2:52 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by MortenK on 11/19/2012 at 2:06 PM
Pass comparer StringComparer.InvariantCultureIgnoreCase to the FindAll / OrderBy methods
File Name Submitted By Submitted On File Size  
BugDemo.zip 11/19/2012 49 KB