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
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.
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.