2017-09-06 16 views
0

UnityからWCFプロジェクトにインターセプタを設定しています。サービスからメソッドを呼び出すと、System.StackOverflowExceptionが返されます。これは私が設定したインターセプタから来ますが、私はそれを解決する方法がわかりません。 FYIWCFのUnityインターセプタでSystem.StackOverflowExceptionを取得する

:私はcircular dependancyまたはa non-terminating recursion

を持っていた場合、私はここでは、Webサービス

のコード

工場だ私はユニティV4とUnity.WCF v3.0の

を使用しています確認してください

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); 

    } 
} 

マイ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; 
    } 
} 

私のウェブサービスのメソッドを呼び出すたびにAn unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dllが得られる理由は何ですか?

トレース

enter image description here

あなたはより多くの情報が必要な場合はお気軽にお問い合わせください。


UPDATE私はインターセプタを削除する場合は、もちろん私が持っていない

例外はもう助けを

感謝:

container.RegisterTypes(AllClasses.FromAssemblies(lstAssemblyToLoad), 
           WithMappings.FromAllInterfaces, 
           WithName.Default, 
           WithLifetime.ContainerControlled, 
           null, 
           overwriteExistingMappings: true); 

しかし、私はちょうどWithName.Defaultに変更した場合WithName.TypeNameとインターセプタを保つ、私は例外を取得しない...私は理由を理解していない...

container.RegisterTypes(AllClasses.FromAssemblies(lstAssemblyToLoad), 
           WithMappings.FromAllInterfaces, 
           WithName.TypeName, 
           WithLifetime.ContainerControlled, 
           getInjectionMembers: c => new InjectionMember[] 
           { 
            new Interceptor<VirtualMethodInterceptor>(), 
            new InterceptionBehavior<ExceptionInterceptionBehavior>() 
           }, 
           overwriteExistingMappings: true); 
+0

例外スタックトレースを共有できますか? – Dhawalk

+0

私が得たもののスクリーンショットで答えを更新しました –

+0

これは完全なスタックではないと思います。さらに下にスクロールすると、コードから始まるものがありますか? – Dhawalk

答えて

0

私は WithName.TypeNameまたは t => t.GetType().NamegetNameを設定するが、今、私はマッピングの問題に直面してることで、回避策を見つけました:)

を、これはStackOverflowExceptionを解いている理由私はまだわかりませんが。誰かが知っているなら、私は彼にクッキーを渡すでしょう。

EDIT 私の同僚で、私たちはそれを検討し、だから我々は

public static class TypeFiltres 
{ 
    public static IEnumerable<Type> WithMatchingInterface(this IEnumerable<Type> types) 
    { 
     return types.Where(type => 
      type.GetTypeInfo().GetInterface("I" + type.Name) != null); 
    } 
} 

新しいタイプのフィルターを追加し、この

のようなWCF工場に設定を変更し、このソリューションに Registration by convention and interception causes ResolutionFailedException

を見つけました

container.RegisterTypes(AllClasses.FromAssemblies(lstAssemblyToLoad).WithMatchingInterface(), 
           WithMappings.FromMatchingInterface, 
           WithName.Default, 
           WithLifetime.ContainerControlled, 
           getInjectionMembers: c => new InjectionMember[] 
           { 
            new Interceptor<InterfaceInterceptor>(), 
            new InterceptionBehavior<ExceptionInterceptionBehavior>() 
           }); 
関連する問題