No exception is thrown if libsodium is not found
If the runtime does not find libsodium, the program will hang and not give a reasonable exception. I have gotten around this temporairly by testing on startup that all the libraries are loaded by calling on their version string:
class DependencyHelper
{
[DllImport("opus", EntryPoint = "opus_get_version_string", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr OpusVersionString();
[DllImport("libsodium", EntryPoint = "sodium_version_string", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr SodiumVersionString();
public static void TestDependencies()
{
string opusVersion = Marshal.PtrToStringAnsi(OpusVersionString());
Console.WriteLine($"Loaded opus with version string: {opusVersion}");
string sodiumVersion = Marshal.PtrToStringAnsi(SodiumVersionString());
Console.WriteLine($"Loaded sodium with version string: {sodiumVersion}");
}
}
I'm assuming it doens't throw any exception because the call to libsodium is in an unsafe class.
The runtime throws when it fails to load a DLL, the fact that it's in an unsafe class doesn't change anything. Something else is at fault here, most likely.
@FiniteReality for the record, it was the docker container that froze. This also happens when I try play voice as part of the tutorial here.
Does it happen outside of Docker? It may be a docker issue causing libs to load weirdly
Same happens on Windows. I found this out when I opened procmon and looked if all the libraries were actually loaded. libsodium was not found. After moving it to the right place, and installing libopus-dev, voice was working fine. (The docker container still hangs, but thats most likely related to something else than this issue)
If that's the case, it may be best for you to compile D.Net yourself and breakpoint the places where we call into libopus and libsodium, to step through and see if there really is an issue or not.
The exception shows up in the event viewer in VS, but does not get propagated to the caller:
Exception thrown: 'System.DllNotFoundException' in Discord.Net.WebSocket.dll ("Unable to load DLL 'libsodium': The specified module could not be found. (Exception from HRESULT: 0x8007007E)") System.DllNotFoundException
> Discord.Net.WebSocket.dll!Discord.Audio.SecretBox.Encrypt(byte[] input = {unknown}, int inputOffset = {unknown}, int inputLength = {unknown}, byte[] output = {unknown}, int outputOffset = {unknown}, byte[] nonce = {unknown}, byte[] secret = {unknown}) C#
Discord.Net.WebSocket.dll!<WriteAsync>d__8.MoveNext() C#
[External Code]
Discord.Net.WebSocket.dll!Discord.Audio.Streams.SodiumEncryptStream.WriteAsync(byte[] buffer = {unknown}, int offset = {unknown}, int count = {unknown}, System.Threading.CancellationToken cancelToken = {unknown}) C#
[External Code]
Discord.Net.WebSocket.dll!<WriteAsync>d__9.MoveNext() C#
[External Code]
Discord.Net.WebSocket.dll!Discord.Audio.Streams.RTPWriteStream.WriteAsync(byte[] buffer = {unknown}, int offset = {unknown}, int count = {unknown}, System.Threading.CancellationToken cancelToken = {unknown}) C#
[External Code]
Discord.Net.WebSocket.dll!<<Run>b__19_0>d.MoveNext() C#
[External Code]