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