@@ -353,8 +353,14 @@ internal ResolveDelegate<BuilderContext> ResolvingFactory(ref BuilderContext con
353353 {
354354 context . RequiresRecovery ? . Recover ( ) ;
355355
356- throw new ResolutionFailedException ( context . RegistrationType , context . Name ,
357- "For more information add Diagnostic extension: Container.AddExtension(new Diagnostic())" , ex ) ;
356+ if ( ! ( ex . InnerException is InvalidRegistrationException ) &&
357+ ! ( ex is InvalidRegistrationException ) &&
358+ ! ( ex is ObjectDisposedException ) &&
359+ ! ( ex is MemberAccessException ) &&
360+ ! ( ex is MakeGenericTypeFailedException ) )
361+ throw ;
362+
363+ throw new ResolutionFailedException ( context . RegistrationType , context . Name , CreateMessage ( ex ) , ex ) ;
358364 }
359365
360366 return context . Existing ;
@@ -380,6 +386,7 @@ private object ExecuteValidatingPlan(ref BuilderContext context)
380386 catch ( Exception ex )
381387 {
382388 context . RequiresRecovery ? . Recover ( ) ;
389+
383390 ex . Data . Add ( Guid . NewGuid ( ) , null == context . Name
384391 ? context . RegistrationType == context . Type
385392 ? ( object ) context . Type
@@ -388,64 +395,12 @@ private object ExecuteValidatingPlan(ref BuilderContext context)
388395 ? ( object ) new Tuple < Type , string > ( context . Type , context . Name )
389396 : new Tuple < Type , Type , string > ( context . RegistrationType , context . Type , context . Name ) ) ;
390397
391- var builder = new StringBuilder ( ) ;
392- builder . AppendLine ( ex . Message ) ;
393- builder . AppendLine ( "_____________________________________________________" ) ;
394- builder . AppendLine ( "Exception occurred while:" ) ;
395- builder . AppendLine ( ) ;
396-
397- var indent = 0 ;
398- foreach ( DictionaryEntry item in ex . Data )
399- {
400- for ( var c = 0 ; c < indent ; c ++ ) builder . Append ( " " ) ;
401- builder . AppendLine ( CreateErrorMessage ( item . Value ) ) ;
402- indent += 1 ;
403- }
404-
405- var message = builder . ToString ( ) ;
398+ var message = CreateDiagnosticMessage ( ex ) ;
406399
407400 throw new ResolutionFailedException ( context . RegistrationType , context . Name , message , ex ) ;
408401 }
409402
410403 return context . Existing ;
411-
412-
413- string CreateErrorMessage ( object value )
414- {
415- switch ( value )
416- {
417- case ParameterInfo parameter :
418- return $ " for parameter: '{ parameter . Name } '";
419-
420- case ConstructorInfo constructor :
421- var ctorSignature = string . Join ( ", " , constructor . GetParameters ( ) . Select ( p => $ "{ p . ParameterType . Name } { p . Name } ") ) ;
422- return $ "on constructor: { constructor . DeclaringType . Name } ({ ctorSignature } )";
423-
424- case MethodInfo method :
425- var methodSignature = string . Join ( ", " , method . GetParameters ( ) . Select ( p => $ "{ p . ParameterType . Name } { p . Name } ") ) ;
426- return $ " on method: { method . Name } ({ methodSignature } )";
427-
428- case PropertyInfo property :
429- return $ " for property: '{ property . Name } '";
430-
431- case FieldInfo field :
432- return $ " for field: '{ field . Name } '";
433-
434- case Type type :
435- return $ "·resolving type: '{ type . Name } '";
436-
437- case Tuple < Type , string > tuple :
438- return $ "resolving type: '{ tuple . Item1 . Name } ' registered with name: '{ tuple . Item2 } '";
439-
440- case Tuple < Type , Type > tuple :
441- return $ "resolving type: '{ tuple . Item1 ? . Name } ' mapped to '{ tuple . Item2 ? . Name } '";
442-
443- case Tuple < Type , Type , string > tuple :
444- return $ "resolving type: '{ tuple . Item1 ? . Name } ' mapped to '{ tuple . Item2 ? . Name } ' and registered with name: '{ tuple . Item3 } '";
445- }
446-
447- return value . ToString ( ) ;
448- }
449404 }
450405
451406 #endregion
@@ -529,7 +484,7 @@ object GetPerResolveValue(IntPtr parent, Type registrationType, string name)
529484 if ( LifetimeManager . NoValue != result ) return result ;
530485
531486 throw new InvalidOperationException ( $ "Circular reference for Type: { parentRef . Type } , Name: { parentRef . Name } ",
532- new CircularDependencyException ( ) ) ;
487+ new CircularDependencyException ( parentRef . Type , parentRef . Name ) ) ;
533488 }
534489 }
535490#endif
@@ -552,8 +507,7 @@ internal static object ContextValidatingResolvePlan(ref BuilderContext thisConte
552507 {
553508 var parentRef = Unsafe . AsRef < BuilderContext > ( parent . ToPointer ( ) ) ;
554509 if ( thisContext . RegistrationType == parentRef . RegistrationType && thisContext . Name == parentRef . Name )
555- throw new InvalidOperationException ( $ "Circular reference for Type: { thisContext . Type } , Name: { thisContext . Name } ",
556- new CircularDependencyException ( ) ) ;
510+ throw new CircularDependencyException ( thisContext . Type , thisContext . Name ) ;
557511
558512 parent = parentRef . Parent ;
559513 }
0 commit comments