Connection problem with c# and .NETCore 3.1

I run self-hosted MongoDB standalone and ReplicaSet on CentOS machines.
My clients are written in C# against .NETCore, I use Fedora 32 to develop my servers. The server exist for several years now.

I upgraded from .NETCore 2.1. to 3.1 without any problems.

I upgraded to the latest MongoDB Driver WITH SOME PROBLEMS…

So the driver I use is 2.11.0.0. This seams to be the first driver supporting .NET Standard 2.0…

I have a connect string to a Standalone Installation which looks as follows and is very simple (no options):

mongodb://bb-infraserver.gala.int:37017

I use this URL on 4 of my servers WITHOUT ANY problems.

But ONE Server throws the following exception (which I have never seen before…). Here is the simple C# code

try
{
	var client = new MongoClient("mongodb://bb-infraserver.gala.int:37017");
}
catch (Exception e)
{
	Log.Logger.Error($"MongoDB driver exception: {e.Message}. Exceptions: {e.GetAllExceptions()}");
	throw;
}

This is the exception which is thrown:

System.IO.IOException: Invalid argument
  at System.IO.FileStream.CheckFileCall(Int64 result, Boolean ignoreNotSupported) in /_/src/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs:828
  at System.IO.FileStream.ReadNative(Span`1 buffer) in /_/src/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs:495
  at System.IO.FileStream.ReadSpan(Span`1 destination) in /_/src/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs:418
  at System.IO.FileStream.Read(Byte[] array, Int32 offset, Int32 count) in /_/src/System.Private.CoreLib/shared/System/IO/FileStream.cs:304
  at System.IO.StreamReader.ReadBuffer() in /_/src/System.Private.CoreLib/shared/System/IO/StreamReader.cs:594
  at System.IO.StreamReader.ReadToEnd() in /_/src/System.Private.CoreLib/shared/System/IO/StreamReader.cs:415
  at System.IO.File.InternalReadAllText(String path, Encoding encoding) in /_/src/System.IO.FileSystem/src/System/IO/File.cs:296
  at System.IO.File.ReadAllText(String path) in /_/src/System.IO.FileSystem/src/System/IO/File.cs:274
  at System.Net.NetworkInformation.StringParsingHelpers.ParseRawLongFile(String filePath) in /_/src/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Misc.cs:64
  at System.Net.NetworkInformation.LinuxNetworkInterface.GetSpeed(String name) in /_/src/System.Net.NetworkInformation/src/System/Net/NetworkInformation/LinuxNetworkInterface.cs:202

I tried to debug this a bit deeper and found a file LinuxNetworkInterface.cs and there a method

private static long? GetSpeed(string name)
{
	try
	{
		string path = Path.Combine(NetworkFiles.SysClassNetFolder, name, NetworkFiles.SpeedFileName);
		long megabitsPerSecond = StringParsingHelpers.ParseRawLongFile(path);
		return megabitsPerSecond == -1
			? megabitsPerSecond
			: megabitsPerSecond * 1_000_000; // Value must be returned in bits per second, not megabits.
	}
	catch (Exception) // Ignore any problems accessing or parsing the file.
	{
		return null;
	}
}

This method is called when doing name resolution which seems to have its origin from a method in the MongoDB driver called MongoUrlBuilder.Parse(). The value of the passed name parameter is “Io” and then it crashes when it tries to build the path with the above exception. This does NOT happen with any of the 2.10.x drivers which support only .NETStandard 1.5.

I must say that my MongoDB servers are still Version 4.0.

Any idea what the problem could be?

I have downgraded the driver to 2.10.4. Now I can create a MongoClient instance without a problem, but when the driver ties to access a database for the first time it crashes with the following exception:

System.PlatformNotSupportedException: Socket.IOControl handles Windows-specific control codes and is not supported on this platform.
  at System.Net.Sockets.SocketPal.WindowsIoctl(SafeSocketHandle handle, Int32 ioControlCode, Byte[] optionInValue, Byte[] optionOutValue, Int32& optionLength) in /_/src/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs:1075
  at System.Net.Sockets.Socket.IOControl(Int32 ioControlCode, Byte[] optionInValue, Byte[] optionOutValue) in /_/src/System.Net.Sockets/src/System/Net/Sockets/Socket.cs:1753
  at System.Net.Sockets.Socket.IOControl(IOControlCode ioControlCode, Byte[] optionInValue, Byte[] optionOutValue) in /_/src/System.Net.Sockets/src/System/Net/Sockets/Socket.cs:1768
  at at MongoDB.Driver.Core.Connections.TcpStreamFactory.CreateSocket(EndPoint endPoint)

Looks like the driver has a problem running on a Linux (I am running Fedora 32 as dev workstation and Centos 7 as OS for all MongoDB servers.

Problem solved (at least for the moment).
Don’t know what caused it but after upgrading the OS (Fedora 31 to 32, the .NETCore SDK and almost all libraries used in the project) some data on the disk must be messed up. I cleared all caches and wrote a script which removed all bin and obj folders of all my server and library projects. Then restarted the Fedora VM and recompiled everything. Problem is gone since then…