Skip to content

Commit 9f1f3a4

Browse files
Improve assembly resolution speed
1 parent 86384bc commit 9f1f3a4

File tree

2 files changed

+32
-37
lines changed

2 files changed

+32
-37
lines changed

api/AltV.Net.Async/AltV.Net.Async.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
<RepositoryUrl>https://github.com/altmp-csharp/docs</RepositoryUrl>
1313
<RepositoryType>git</RepositoryType>
1414
<PackageTags>altv gta bridge</PackageTags>
15-
<PackageVersion>1.13.0</PackageVersion>
15+
<PackageVersion>1.13.1</PackageVersion>
1616
<PackageLicenseFile>license.txt</PackageLicenseFile>
17-
<PackageReleaseNotes></PackageReleaseNotes>
17+
<PackageReleaseNotes>Fix multi async resources</PackageReleaseNotes>
1818
</PropertyGroup>
1919

2020
<ItemGroup>

api/AltV.Net.Host/ResourceAssemblyLoadContext.cs

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,51 @@ public class ResourceAssemblyLoadContext : AssemblyLoadContext
99
{
1010
private readonly AssemblyDependencyResolver resolver;
1111

12-
private readonly string resourcePath;
13-
1412
public ResourceAssemblyLoadContext(string resourceDllPath, string resourcePath, string resourceName) : base(resourceName,
1513
true)
1614
{
1715
resolver = new AssemblyDependencyResolver(resourceDllPath);
18-
this.resourcePath = resourcePath;
16+
Resolving += (context, assemblyName) =>
17+
{
18+
var dllPath = resourcePath + Path.DirectorySeparatorChar + assemblyName.Name;
19+
if (!File.Exists(dllPath)) return null;
20+
try
21+
{
22+
return LoadFromAssemblyPath(dllPath);
23+
}
24+
catch (Exception exception)
25+
{
26+
Console.WriteLine(exception);
27+
}
28+
29+
return null;
30+
};
31+
ResolvingUnmanagedDll += (assembly, unmanagedDllName) =>
32+
{
33+
var dllPath = resourcePath + Path.DirectorySeparatorChar + unmanagedDllName;
34+
if (!File.Exists(dllPath)) return IntPtr.Zero;
35+
try
36+
{
37+
return LoadUnmanagedDllFromPath(dllPath);
38+
}
39+
catch (Exception exception)
40+
{
41+
Console.WriteLine(exception);
42+
}
43+
44+
return IntPtr.Zero;
45+
};
1946
}
2047

2148
protected override Assembly Load(AssemblyName assemblyName)
2249
{
2350
var assemblyPath = resolver.ResolveAssemblyToPath(assemblyName);
24-
if (assemblyPath == null)
25-
{
26-
var dllPath = resourcePath + Path.DirectorySeparatorChar + assemblyName.Name;
27-
if (File.Exists(dllPath))
28-
{
29-
try
30-
{
31-
return LoadFromAssemblyPath(dllPath);
32-
}
33-
catch (Exception exception)
34-
{
35-
Console.WriteLine(exception);
36-
}
37-
}
38-
}
3951
return assemblyPath != null ? LoadFromAssemblyPath(assemblyPath) : null;
4052
}
4153

4254
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
4355
{
4456
var libraryPath = resolver.ResolveUnmanagedDllToPath(unmanagedDllName);
45-
46-
if (libraryPath == null)
47-
{
48-
var dllPath = resourcePath + Path.DirectorySeparatorChar + unmanagedDllName;
49-
if (File.Exists(dllPath))
50-
{
51-
try
52-
{
53-
return LoadUnmanagedDllFromPath(dllPath);
54-
}
55-
catch (Exception exception)
56-
{
57-
Console.WriteLine(exception);
58-
}
59-
}
60-
}
61-
6257
return libraryPath != null ? LoadUnmanagedDllFromPath(libraryPath) : IntPtr.Zero;
6358
}
6459
}

0 commit comments

Comments
 (0)