@@ -38,6 +38,7 @@ protected ScriptHost(ScriptHostConfiguration scriptConfig)
38
38
{
39
39
ScriptConfig = scriptConfig ;
40
40
FunctionErrors = new Dictionary < string , Collection < string > > ( StringComparer . OrdinalIgnoreCase ) ;
41
+ NodeFunctionInvoker . UnhandledException += OnUnhandledException ;
41
42
}
42
43
43
44
public TraceWriter TraceWriter { get ; private set ; }
@@ -203,8 +204,6 @@ protected virtual void Initialize()
203
204
new CSharpFunctionDescriptionProvider ( this , ScriptConfig )
204
205
} ;
205
206
206
- NodeFunctionInvoker . UnhandledException += OnUnhandledException ;
207
-
208
207
// read all script functions and apply to JobHostConfiguration
209
208
Collection < FunctionDescriptor > functions = ReadFunctions ( ScriptConfig , descriptionProviders ) ;
210
209
string defaultNamespace = "Host" ;
@@ -221,26 +220,6 @@ protected virtual void Initialize()
221
220
Functions = functions ;
222
221
}
223
222
224
- private void OnUnhandledException ( object sender , UnhandledExceptionEventArgs e )
225
- {
226
- HandleHostError ( ( Exception ) e . ExceptionObject ) ;
227
- }
228
-
229
- // Bindings may require us to update JobHostConfiguration.
230
- private static void ApplyBindingConfiguration ( Collection < FunctionDescriptor > functions , JobHostConfiguration hostConfig )
231
- {
232
- JobHostConfigurationBuilder builder = new JobHostConfigurationBuilder ( hostConfig ) ;
233
-
234
- foreach ( var func in functions )
235
- {
236
- foreach ( var metadata in func . Metadata . InputBindings . Concat ( func . Metadata . OutputBindings ) )
237
- {
238
- metadata . ApplyToConfig ( builder ) ;
239
- }
240
- }
241
- builder . Done ( ) ;
242
- }
243
-
244
223
public static ScriptHost Create ( ScriptHostConfiguration scriptConfig = null )
245
224
{
246
225
if ( scriptConfig == null )
@@ -659,6 +638,26 @@ internal static void ApplyConfiguration(JObject config, ScriptHostConfiguration
659
638
hostConfig . UseCore ( ) ;
660
639
}
661
640
641
+ private void OnUnhandledException ( object sender , UnhandledExceptionEventArgs e )
642
+ {
643
+ HandleHostError ( ( Exception ) e . ExceptionObject ) ;
644
+ }
645
+
646
+ // Bindings may require us to update JobHostConfiguration.
647
+ private static void ApplyBindingConfiguration ( Collection < FunctionDescriptor > functions , JobHostConfiguration hostConfig )
648
+ {
649
+ JobHostConfigurationBuilder builder = new JobHostConfigurationBuilder ( hostConfig ) ;
650
+
651
+ foreach ( var func in functions )
652
+ {
653
+ foreach ( var metadata in func . Metadata . InputBindings . Concat ( func . Metadata . OutputBindings ) )
654
+ {
655
+ metadata . ApplyToConfig ( builder ) ;
656
+ }
657
+ }
658
+ builder . Done ( ) ;
659
+ }
660
+
662
661
private void HandleHostError ( Microsoft . Azure . WebJobs . Extensions . TraceFilter traceFilter )
663
662
{
664
663
foreach ( TraceEvent traceEvent in traceFilter . Events )
@@ -822,6 +821,8 @@ protected override void Dispose(bool disposing)
822
821
{
823
822
( ( IDisposable ) TraceWriter ) . Dispose ( ) ;
824
823
}
824
+
825
+ NodeFunctionInvoker . UnhandledException -= OnUnhandledException ;
825
826
}
826
827
}
827
828
}
0 commit comments