Skip to content

Commit afed9ec

Browse files
Fix native dll loading
1 parent dd8da7a commit afed9ec

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ RUN cd AltV.Net.Chat && dotnet publish -c Release
3333
#FROM debian:stable
3434
FROM ubuntu:18.04
3535

36+
COPY --from=dotnet /usr/share/dotnet /usr/share/dotnet
37+
3638
RUN apt-get update
3739
RUN apt-get install -y apt-utils
3840
RUN apt-get install -y libc6-i386
@@ -50,6 +52,9 @@ COPY start.sh .
5052
COPY startgdb.sh .
5153
COPY libnode.so.64 .
5254
COPY libnode-module.so modules/
55+
56+
COPY csharp-module.dll resources/example/2csharp-module.dll
57+
5358
COPY resource.cfg resources/example/
5459
COPY --from=dotnet /altv-example/AltV.Net.Chat/resource.cfg resources/chat/
5560
COPY data/ ./data
@@ -58,7 +63,6 @@ COPY --from=clang /runtime/build/src/libcsharp-module.so modules/
5863
COPY --from=dotnet /altv-example/AltV.Net.Example/bin/Release/netcoreapp3.0/publish resources/example/
5964
COPY --from=dotnet /altv-example/AltV.Net.Chat/bin/Release/netcoreapp3.0/publish resources/chat/
6065
COPY --from=dotnet /altv-example/AltV.Net.Host/bin/Release/netcoreapp3.0/publish .
61-
COPY --from=dotnet /usr/share/dotnet /usr/share/dotnet
6266
RUN ls -l
6367
RUN chmod +x ./altv-server
6468

api/AltV.Net.Host/Host.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static int ExecuteResource(IntPtr arg, int argLength)
4646
var resourceMain = Marshal.PtrToStringUTF8(libArgs.ResourceMain);
4747

4848
var resourceDllPath = GetPath(resourcePath, resourceMain);
49-
var resourceAssemblyLoadContext = new ResourceAssemblyLoadContext(resourceDllPath, resourceName);
49+
var resourceAssemblyLoadContext = new ResourceAssemblyLoadContext(resourceDllPath, resourcePath, resourceName);
5050

5151
Assembly resourceAssembly;
5252

api/AltV.Net.Host/ResourceAssemblyLoadContext.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ public class ResourceAssemblyLoadContext : AssemblyLoadContext
1111

1212
private readonly string resourceName;
1313

14-
public ResourceAssemblyLoadContext(string resourcePath, string resourceName) : base(resourceName)
14+
private readonly string resourcePath;
15+
16+
public ResourceAssemblyLoadContext(string resourceDllPath, string resourcePath, string resourceName) : base(resourceName,
17+
true)
1518
{
16-
resolver = new AssemblyDependencyResolver(resourcePath);
19+
resolver = new AssemblyDependencyResolver(resourceDllPath);
1720
this.resourceName = resourceName;
21+
this.resourcePath = resourcePath;
1822
}
1923

2024
protected override Assembly Load(AssemblyName assemblyName)
@@ -25,10 +29,23 @@ protected override Assembly Load(AssemblyName assemblyName)
2529

2630
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
2731
{
28-
var libraryPath = resolver.ResolveUnmanagedDllToPath(unmanagedDllName) ??
29-
resolver.ResolveUnmanagedDllToPath(
30-
"resources" + Path.DirectorySeparatorChar + resourceName +
31-
Path.DirectorySeparatorChar + unmanagedDllName);
32+
var libraryPath = resolver.ResolveUnmanagedDllToPath(unmanagedDllName);
33+
34+
if (libraryPath == null)
35+
{
36+
var dllPath = resourcePath + Path.DirectorySeparatorChar + unmanagedDllName;
37+
if (File.Exists(dllPath))
38+
{
39+
try
40+
{
41+
return LoadUnmanagedDllFromPath(dllPath);
42+
}
43+
catch (Exception exception)
44+
{
45+
Console.WriteLine(exception);
46+
}
47+
}
48+
}
3249

3350
return libraryPath != null ? LoadUnmanagedDllFromPath(libraryPath) : IntPtr.Zero;
3451
}

api/AltV.Net/ModuleWrapper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Runtime.CompilerServices;
34
using System.Runtime.Loader;
45
using AltV.Net.Elements.Args;

0 commit comments

Comments
 (0)