33using System . IO ;
44using System . Reflection ;
55using System . Runtime . CompilerServices ;
6+ using System . Runtime . Loader ;
67using System . Text ;
78using System . Threading ;
89using TestMyCode . CSharp . Core . Data ;
@@ -33,10 +34,10 @@ public void RunAssemblies(IReadOnlyList<Assembly> assemblies)
3334
3435 public void RunAssemblyTests ( Assembly assembly )
3536 {
36- using ManualResetEvent testsCompled = new ManualResetEvent ( false ) ;
37- using AssemblyRunner runner = AssemblyRunner . WithoutAppDomain ( assembly . Location ) ;
37+ using AssemblyLoadContext . ContextualReflectionScope scope = AssemblyLoadContext . EnterContextualReflection ( assembly ) ;
3838
39- AppDomain . CurrentDomain . AssemblyResolve += this . CreateTestAssemblyResolver ( assembly ) ;
39+ using ManualResetEvent testsCompleted = new ManualResetEvent ( false ) ;
40+ using AssemblyRunner runner = AssemblyRunner . WithoutAppDomain ( assembly . Location ) ;
4041
4142 runner . OnTestFailed += info =>
4243 {
@@ -52,39 +53,20 @@ public void RunAssemblyTests(Assembly assembly)
5253
5354 runner . OnExecutionComplete += info =>
5455 {
55- testsCompled . Set ( ) ;
56+ testsCompleted . Set ( ) ;
5657 } ;
5758
5859 //This is non blocking call!
5960 runner . Start ( ) ;
6061
6162 //We don't want to exit before all of the tests have ran
6263 //This will be signaled once all of the tests have been ran
63- testsCompled . WaitOne ( ) ;
64+ testsCompleted . WaitOne ( ) ;
6465
6566 //OnExecutionComplete is invoked before setting the Status so spin here until it changes
6667 SpinWait . SpinUntil ( ( ) => runner . Status == AssemblyRunnerStatus . Idle ) ;
6768 }
6869
69- private ResolveEventHandler CreateTestAssemblyResolver ( Assembly assembly )
70- {
71- return ( sender , args ) =>
72- {
73- AssemblyName name = new AssemblyName ( args . Name ! ) ;
74-
75- string assemblyName = $ "{ name . Name } .dll";
76- string dir = Path . GetDirectoryName ( assembly . Location ) ! ;
77-
78- string assemblyFile = Path . Combine ( dir , assemblyName ) ;
79- if ( File . Exists ( assemblyFile ) )
80- {
81- return Assembly . LoadFile ( assemblyFile ) ;
82- }
83-
84- return null ;
85- } ;
86- }
87-
8870 private void AddTestResult ( MethodTestResult result )
8971 {
9072 //We lock here to ensure that we don't have any race conditions
0 commit comments