@@ -492,10 +492,9 @@ private static Registration CreateCrossWireRegistration(
492492 return registration ;
493493 }
494494
495- private static Func < object > BuildSingletonInstanceCreator (
496- Type serviceType , IServiceProvider rootProvider )
495+ private static Func < object > BuildSingletonInstanceCreator ( Type serviceType , IServiceProvider rootProvider )
497496 {
498- return ( ) => rootProvider . GetRequiredService ( serviceType ) ;
497+ return ( ) => GetRequiredService ( rootProvider , serviceType ) ;
499498 }
500499
501500 private static Func < object > BuildScopedInstanceCreator (
@@ -524,10 +523,28 @@ private static Func<object> BuildScopedInstanceCreator(
524523 $ "Error resolving the cross-wired { serviceType . ToFriendlyName ( ) } . { ex . Message } ", ex ) ;
525524 }
526525
527- return current . GetRequiredService ( serviceType ) ;
526+ return GetRequiredService ( current , serviceType ) ;
528527 } ;
529528 }
530529
530+ private static object GetRequiredService ( IServiceProvider provider , Type serviceType )
531+ {
532+ try
533+ {
534+ return provider . GetRequiredService ( serviceType ) ;
535+ }
536+ catch ( Exception ex )
537+ {
538+ throw new InvalidOperationException (
539+ $ "Failed to resolve { serviceType . ToFriendlyName ( ) } . { serviceType . ToFriendlyName ( ) } is a " +
540+ $ "cross-wired service, meaning that Simple Injector forwarded the request the framework's " +
541+ $ "IServiceProvider in order to get an instance. The used { provider . GetType ( ) . FullName } , " +
542+ $ "however, failed with the following message: \" { ex . Message } \" . This error might indicate a " +
543+ $ "misconfiguration of services in the framework's IServiceCollection.",
544+ ex ) ;
545+ }
546+ }
547+
531548 private static ServiceDescriptor ? FindServiceDescriptor ( IServiceCollection services , Type serviceType )
532549 {
533550 // In case there are multiple descriptors for a given type, .NET Core will use the last
0 commit comments