Closed adamjez closed 4 years ago
Wow, that is very odd. I can only thing that the linux .NET SDK doesn't have all the StringComparer
types.
I'm not using linux so could you get a list of the static values in the StringComparer
on linux .NET SDK. Thanks.
I made simple console app targetting netcoreapp3.1
in ubuntu (mcr.microsoft.com/dotnet/core/sdk:3.1-bionic) docker image:
var comparers = new[]
{
(str: "Ordinal", comp: StringComparer.Ordinal),
(str: "OrdinalIgnoreCase", comp: StringComparer.OrdinalIgnoreCase),
(str: "CurrentCultureIgnoreCase", comp: StringComparer.CurrentCultureIgnoreCase),
(str: "CurrentCulture", comp: StringComparer.CurrentCulture),
(str: "InvariantCulture", comp: StringComparer.InvariantCulture),
(str: "InvariantCultureIgnoreCase", comp: StringComparer.InvariantCultureIgnoreCase),
};
var pairs = /* I removed the code for the code sample brevity */
string output = "";
foreach (var (first, second) in pairs)
{
var areEqual = first.comp.Equals(second.comp);
if (areEqual)
{
output += $"{first.comp.GetType().Name} ({first.str}) is equal to {second.comp.GetType().Name} ({second.str})\n";
}
}
Console.WriteLine(output);
outputs:
CultureAwareComparer (CurrentCultureIgnoreCase) is equal to CultureAwareComparer (InvariantCultureIgnoreCase)
CultureAwareComparer (CurrentCulture) is equal to CultureAwareComparer (InvariantCulture)
In the case of Windows the console output is empty.
The easiest fix I can think of is to use switch
expression instead of Dictionary
.
That is great information, and a very sensible suggestion of a switch. I will try an look at this soon, but I have a few things to do next, I'll let you know when I have released a new NuGet.
Hi @adamjez,
I have released a new version on NuGet (3.1.1) which contains a fix to your problem. Had to use istacked ifs instead of switch as I needed to do an .Equal to compare the StringComparer
.
Please try this update and let me know if it works.
Hi @JonPSmith, It works :-) Thank you!
Hi,
I am using nuget
EfCore.TestSupport
with latest 3.1.0 version.I get unhandled exception thrown when constructing
new CompareEfSql()
.I run similar test to test
CompareViaContext
inComparerBooks
class. If I run it on windows it completes without error but on linux (ubuntu 18.04) it throws following error:Full stack trace:
It seems that some keys in dictionary ComparerToComparison are equal to each other which is strange.