@@ -487,15 +487,25 @@ private async Task<IModuleResult> ExecuteTypedModule(
487487 var resultType = module . ResultType ;
488488
489489 // Use reflection to call the generic ExecuteAsync method
490- var executeMethod = typeof ( IModuleExecutionPipeline ) . GetMethod ( nameof ( IModuleExecutionPipeline . ExecuteAsync ) ) !
491- . MakeGenericMethod ( resultType ) ;
490+ var executeMethodInfo = typeof ( IModuleExecutionPipeline ) . GetMethod ( nameof ( IModuleExecutionPipeline . ExecuteAsync ) )
491+ ?? throw new InvalidOperationException ( $ "Method ' { nameof ( IModuleExecutionPipeline . ExecuteAsync ) } ' not found on type ' { nameof ( IModuleExecutionPipeline ) } '." ) ;
492492
493- var task = ( Task ) executeMethod . Invoke ( _executionPipeline , new object [ ] { module , executionContext , moduleContext , cancellationToken } ) ! ;
493+ var executeMethod = executeMethodInfo . MakeGenericMethod ( resultType ) ;
494+
495+ var invokeResult = executeMethod . Invoke ( _executionPipeline , new object [ ] { module , executionContext , moduleContext , cancellationToken } )
496+ ?? throw new InvalidOperationException ( $ "Invocation of '{ nameof ( IModuleExecutionPipeline . ExecuteAsync ) } ' returned null.") ;
497+
498+ var task = ( Task ) invokeResult ;
494499 await task ;
495500
496501 // Get the result from the completed task
497- var resultProperty = task . GetType ( ) . GetProperty ( "Result" ) ! ;
498- return ( IModuleResult ) resultProperty . GetValue ( task ) ! ;
502+ var resultProperty = task . GetType ( ) . GetProperty ( "Result" )
503+ ?? throw new InvalidOperationException ( $ "Property 'Result' not found on task type '{ task . GetType ( ) . Name } '.") ;
504+
505+ var resultValue = resultProperty . GetValue ( task )
506+ ?? throw new InvalidOperationException ( $ "Property 'Result' returned null for task type '{ task . GetType ( ) . Name } '.") ;
507+
508+ return ( IModuleResult ) resultValue ;
499509 }
500510
501511 private async Task < IDisposable > WaitForParallelLimiter ( Type moduleType )
0 commit comments