The following code compiles locally on Windows , but fails in a linux docker container. Both are using the .NET 8 SDK. The request.SearchText property is of type string?.
var searches = request.SearchText?.Split([',',' ',';','n'],
StringSplitOptions.TrimEntries |
StringSplitOptions.RemoveEmptyEntries).ToList() ?? [];
This error is received in docker Linux:
error CS0121: The call is ambiguous between the following methods or
properties: 'string.Split(char[]?, StringSplitOptions)' and
'string.Split(string?, StringSplitOptions)' [/src/....]
It seems to be unable to resolve to the same string.Split overload as when on Windows. Explicitly declaring the type of the array will fix the compilation error:
char[]? separator = [',',' ',';','n'];
var searches = request.SearchText?
.Split(separator, StringSplitOptions.TrimEntries |
StringSplitOptions.RemoveEmptyEntries)
.ToList() ?? [];
Why is the compiler unable to resolve to the same string.Split function on linux? Note: This is part of a large project so there might be other variables at play.
7
net8.0 in the project file. 8.0.304 is installed locally. The docker build is using 8.0.201-jammy-sdk.
This seems to be a bug in 8.0.2xx
versions of the SDK. If you install it on your Windows machine and use global.json
to pin the version and disable roll-forwarding (verify by invoking dotnet --version
in terminal from the project root):
{
"sdk": {
"version": "8.0.200",
"rollForward": "Disable"
}
}
You will get the same error (reproduced on my Windows machine), but updating to later SDK will fix it (checked with 8.0.304
and 8.0.401
). So you need to update the container image(s) to later version.