سؤال

We have developed a sample project to handle all exception by using entlib exception handler block and Unity.

When I try to invoke a method using unity container I am getting the following exception, “Cannot swallow exceptions for methods with non-null return type.”

If we try to invoke a void method its working fine.

Below is the code,

    IUnityContainer unityContainer = new UnityContainer();
            unityContainer.LoadConfiguration("Container1");
            var service2 = unityContainer.Resolve<IABCServices>("Impl1");
            string dd= service2.DoSomething(55);

Its configuration file is given below,

    <alias alias="string" type="System.String, mscorlib"/>
    <alias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />
    <alias alias="transient" type="Microsoft.Practices.Unity.TransientLifetimeManager, Microsoft.Practices.Unity" />
    <alias alias="InterceptionConfigurationExtension" type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Microsoft.Practices.Unity.Interception.Configuration" />
    <alias alias="EnterpriseLibraryCoreExtension" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity.EnterpriseLibraryCoreExtension, Microsoft.Practices.EnterpriseLibrary.Common" />
    <alias alias="ExceptionCallHandler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.PolicyInjection.ExceptionCallHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" />
    <alias alias="IABCServices" type="ABC.GGG.Integration.Contracts.SSSService.Interfaces.IABCServices, ABC.GGG.Integration.Contracts" />
    <alias alias="ABCServices" type="ABC.GGG.Integration.Implementation.SSSService.ABCServices, ABC.GGG.Integration.Implementation" />
    <sectionExtension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Microsoft.Practices.Unity.Interception.Configuration" />

    <container name="Container1">
        <register type="string"></register>
        <extension type="EnterpriseLibraryCoreExtension"/>
        <extension type="Interception" />
        <register type="IABCServices">
            <interceptor isDefaultForType="true" type="TransparentProxyInterceptor"/>
        </register>
        <register name="Impl1" type="IABCServices" mapTo="ABCServices">
            <interceptionBehavior type="PolicyInjectionBehavior"/>
        </register>
        <interception>
            <policy name="MyPolicy">                    
                <matchingRule name="exceptionHandling" type="TypeMatchingRule">
                    <constructor>
                        <param name="typeName">
                            <value value="ABC.GGG.Integration.Contracts.SSSService.Interfaces.IABCServices"  />
                        </param>
                    </constructor>
                </matchingRule>
                    <callHandler name="ExceptionHandlingCallHandler" type="ExceptionCallHandler">
                    <lifetime type="singleton" />
                    <constructor>
                        <param name="exceptionPolicy" dependencyName="Policy" />                            
                    </constructor>
                </callHandler>

            </policy>
        </interception>
        </container>
</unity>

Could anyone please explain how to fix this issue?

هل كانت مفيدة؟

المحلول

non void methods must return something or throw. Message says that you have configuration that tries to swallow exceptions. It probably should be configured to log exceptions and rethrow them.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top