0

我们开发了一个示例项目来使用 entlib 异常处理程序块和 Unity 来处理所有异常。

当我尝试使用统一容器调用方法时,我收到以下异常,“不能吞下具有非空返回类型的方法的异常。”</p>

如果我们尝试调用 void 方法,它的工作正常。

下面是代码,

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

它的配置文件如下,

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

谁能解释一下如何解决这个问题?

4

1 回答 1

0

非 void 方法必须返回一些东西或抛出。消息说您有尝试吞下异常的配置。它可能应该配置为记录异常并重新抛出它们。

于 2013-04-04T05:37:35.333 回答