Je place des intercepteurs d'Unity dans mon projet WCF et j'obtiens un System.StackOverflowException
quand j'appelle une méthode de mon service. Cela vient des intercepteurs que j'ai mis en place mais je ne sais pas comment le résoudre.Obtention de System.StackOverflowException avec l'intercepteur Unity dans WCF
FYI: Je vérifie si j'avais un circular dependancy ou a non-terminating recursion
J'utilise v4 Unity et Unity.WCF v3.0
Voici le code
l'usine pour le service Web
public class WcfServiceFactory : UnityServiceHostFactory
{
protected override void ConfigureContainer(IUnityContainer container)
{
// register all your components with the container here
List<string> lstNomAssemblyToLoad = new List<string>();
List<Assembly> lstAssemblyToLoad;
lstNomAssemblyToLoad.Add("Service");
lstNomAssemblyToLoad.Add("Interfaces");
lstNomAssemblyToLoad.Add("Bll");
lstNomAssemblyToLoad.Add("Dal");
// Loading specific interface from unity.config
container = container.LoadConfiguration();
// Resolving interfaces without explicit declaration
lstAssemblyToLoad = AppDomain.CurrentDomain.GetAssemblies().Where(a => lstNomAssemblyToLoad.Contains(a.GetName().Name)).ToList();
container.AddNewExtension<Interception>();
container.RegisterTypes(AllClasses.FromAssemblies(lstAssemblyToLoad),
WithMappings.FromAllInterfaces,
WithName.Default,
WithLifetime.ContainerControlled,
getInjectionMembers: c => new InjectionMember[]
{
new Interceptor<VirtualMethodInterceptor>(),
new InterceptionBehavior<ExceptionInterceptionBehavior>()
},
overwriteExistingMappings: true);
}
}
Mon InterceptionBehavior
public class ExceptionInterceptionBehavior : IInterceptionBehavior
{
public IEnumerable<Type> GetRequiredInterfaces()
{
return Type.EmptyTypes;
}
public bool WillExecute
{
get { return true; }
}
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
var result = getNext()(input, getNext);
return result;
}
}
Des idées pour lesquelles je reçois An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
chaque fois que j'appelle une méthode de mon service Web?
La trace
Si vous avez besoin de plus amples informations s'il vous plaît ne pas hésiter à demander.
Merci pour l'aide
MISE À JOUR
Si je supprime les intercepteurs, bien sûr, je n'ai pas exception plus:
container.RegisterTypes(AllClasses.FromAssemblies(lstAssemblyToLoad),
WithMappings.FromAllInterfaces,
WithName.Default,
WithLifetime.ContainerControlled,
null,
overwriteExistingMappings: true);
Mais si je change juste WithName.Default
à WithName.TypeName
et garder les intercepteurs, je ne reçois pas d'exception ... Je ne comprends pas pourquoi ...
container.RegisterTypes(AllClasses.FromAssemblies(lstAssemblyToLoad),
WithMappings.FromAllInterfaces,
WithName.TypeName,
WithLifetime.ContainerControlled,
getInjectionMembers: c => new InjectionMember[]
{
new Interceptor<VirtualMethodInterceptor>(),
new InterceptionBehavior<ExceptionInterceptionBehavior>()
},
overwriteExistingMappings: true);
pouvez-vous partager la trace de pile d'exception? – Dhawalk
Mis à jour la réponse avec une capture d'écran de ce que je reçois –
Je ne pense pas que ce soit la pile complète. Si vous descendez plus loin, est-ce que cela commence par votre code? – Dhawalk