[dotnet]how to change dll load path? #2028
Unanswered
shutaozhenzhen
asked this question in
Q&A
Replies: 2 comments
-
|
It is a dynamic library loaded by C# pinvoke. The DllImport attribute has only one dllName parameter. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
You can use private static string? EnvironmentToLibraryName() {
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
return "puerts_macos";
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
return RuntimeInformation.ProcessArchitecture switch {
Architecture.X64 => "puerts_windows_x86_64",
Architecture.X86 => "puerts_windows_x86",
_ => null
};
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && RuntimeInformation.ProcessArchitecture == Architecture.X64) {
return "puerts_linux_x86_64";
}
return null;
}
public static void SetCustomDllImportResolver() {
NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), (name, assembly, path) => {
if (name == "puerts") {
var libraryName = EnvironmentToLibraryName();
if (libraryName is null) {
throw new Exception($"Unsupported puerts library binary for {RuntimeInformation.RuntimeIdentifier} {RuntimeInformation.ProcessArchitecture}");
}
return NativeLibrary.Load(libraryName, assembly, path);
}
return NativeLibrary.Load(name, assembly, path);
});
}
``` |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Trying to use puerts in a unity game dll mod. So I use the PUERTS_GENERAL, but failed to load puerts.dll. How to change the dll load path by dll import?
Beta Was this translation helpful? Give feedback.
All reactions