@@ -34,30 +34,38 @@ public async Task<TReturn> Execute<TReturn>(string dllPath, IEnumerable<string>
34
34
var runtimeDepsMap = ScriptCompiler . CreateScriptDependenciesMap ( runtimeDeps ) ;
35
35
var assembly = Assembly . LoadFrom ( dllPath ) ; // this needs to be called prior to 'AppDomain.CurrentDomain.AssemblyResolve' event handler added
36
36
37
- AppDomain . CurrentDomain . AssemblyResolve += ( sender , args ) => ResolveAssembly ( args , runtimeDepsMap ) ;
37
+ Assembly OnResolve ( object sender , ResolveEventArgs args ) => ResolveAssembly ( args , runtimeDepsMap ) ;
38
38
39
- var type = assembly . GetType ( "Submission#0" ) ;
40
- var method = type . GetMethod ( "<Factory>" , BindingFlags . Static | BindingFlags . Public ) ;
41
-
42
- var globals = new CommandLineScriptGlobals ( ScriptConsole . Out , CSharpObjectFormatter . Instance ) ;
43
- foreach ( var arg in commandLineArgs )
44
- globals . Args . Add ( arg ) ;
45
-
46
- var submissionStates = new object [ 2 ] ;
47
- submissionStates [ 0 ] = globals ;
48
-
49
- var resultTask = method . Invoke ( null , new [ ] { submissionStates } ) as Task < TReturn > ;
39
+ AppDomain . CurrentDomain . AssemblyResolve += OnResolve ;
50
40
try
51
41
{
52
- _ = await resultTask ;
42
+ var type = assembly . GetType ( "Submission#0" ) ;
43
+ var method = type . GetMethod ( "<Factory>" , BindingFl
8000
ags . Static | BindingFlags . Public ) ;
44
+
45
+ var globals = new CommandLineScriptGlobals ( ScriptConsole . Out , CSharpObjectFormatter . Instance ) ;
46
+ foreach ( var arg in commandLineArgs )
47
+ globals . Args . Add ( arg ) ;
48
+
49
+ var submissionStates = new object [ 2 ] ;
50
+ submissionStates [ 0 ] = globals ;
51
+
52
+ var resultTask = method . Invoke ( null , new [ ] { submissionStates } ) as Task < TReturn > ;
53
+ try
54
+ {
55
+ _ = await resultTask ;
56
+ }
57
+ catch ( System . Exception ex )
58
+ {
59
+ ScriptConsole . WriteError ( ex . ToString ( ) ) ;
60
+ throw new ScriptRuntimeException ( "Script execution resulted in an exception." , ex ) ;
61
+ }
62
+
63
+ return await resultTask ;
53
64
}
54
- catch ( System . Exception ex )
65
+ finally
55
66
{
56
- ScriptConsole . WriteError ( ex . ToString ( ) ) ;
57
- throw new ScriptRuntimeException ( "Script execution resulted in an exception." , ex ) ;
67
+ AppDomain . CurrentDomain . AssemblyResolve -= OnResolve ;
58
68
}
59
-
60
- return await resultTask ;
61
69
}
62
70
63
71
public Task < TReturn > Execute < TReturn > ( ScriptContext context )
0 commit comments