Got error, when connecting to Mongo Atlas in unity game server

Hi, I’m making SCP: Secret Laboratory server (C#) and got this error, while trying to connect to Mongo Atlas
MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.MissingMethodException: void System.Security.Cryptography.Rfc2898DeriveBytes..

In fact, it works fine with connections without any auth
Tested on Mongo 2.17.1, 2.18 and 2.19

Do you have any solutions to that?

Welcome to the MongoDB Community Forums.

Rfc2898DeriveBytes is used by SCRAM-SHA1 and SCRAM-SHA256 authenticators. It appears that your runtime does not support this method. We vendor a version of Rfc2898DeriveBytes for netstandard2.0 because it doesn’t include the required method, but netstandard2.1 and net472 should both include that method.

Which .NET version do you compile SCP:SL plugins for? What is the .NET runtime environment version?

Another option to work around the issue is to use a different authentication mechanism such as x509 auth.

Sincerely,
James

1 Like

Hi, @James_Kovacs !
I’m using .NET Framework 4.8 for plugins.

Here is the information on runtime environment:

.NET SDK:
 Version:   7.0.102
 Commit:    4bbdd14480

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.20348
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.102\

Host:
  Version:      7.0.2
  Architecture: x64
  Commit:       d037e070eb

.NET SDKs installed:
  7.0.102 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download```

Regards, Artem

Thanks for providing the runtime environment. You are compiling against .NET 7, which includes the Rfc2898DeriveBytes class. The Unity compiler will strip out what it thinks is unreachable code to reduce the size of the resulting binary and this can lead to a System.MissingMethodException at runtime. However the .NET/C# Driver explicitly uses Rfc2898DeriveBytes and thus it should not be stripped out of the final binary.

I would suggest updating your link.xml file to prevent Rfc2898DeriveBytes from being stripped during the build process. See Managed code stripping in the Unity docs for more information.

Sincerely,
James