【问题标题】:The type ExceptionPolicyImpl has multiple constructors of length 2. Unable to disambiguateExceptionPolicyImpl 类型有多个长度为 2 的构造函数。无法消除歧义
【发布时间】:2012-01-18 07:17:45
【问题描述】:

我有一个配置了 Enterprise Library 5“记录应用程序块”、“验证应用程序块与 WCF 集成”和“异常处理应用程序块 WCF 提供程序”的 WCF 服务,并使用如下流式 API 对其进行配置:

 builder.ConfigureExceptionHandling()
            // -----------------------------------------------------
            // Preventing Enterprise Library Validation Block exceptions from getting shielded.
            // -----------------------------------------------------
            .GivenPolicyWithName("WCF Exception Shielding")
            .ForExceptionType<FaultException<ValidationFault>>()
            .ThenDoNothing()

            // -----------------------------------------------------
            // Shielding unhandled exceptions
            // -----------------------------------------------------
            .ForExceptionType<Exception>()
            .LogToCategory("My Logging Category")
            .WithSeverity(TraceEventType.Critical)
            .ShieldExceptionForWcf(typeof(ServiceUnhandledFault), Resources.UnhandledException_ErrorMessage)
            .ThenThrowNewException();

服务实现:

[ServiceContract]
[ValidationBehavior]
[ExceptionShielding("WCF Exception Shielding")]
public interface IMyService
{
    [OperationContract]
    [FaultContract(typeof(ValidationFault))]
    [FaultContract(typeof(ServiceUnhandledFault))]
    void InsertEntity(MyEntity file);
}

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)]
public partial class MyService : IMyService { ...Implementation... }

如果我将服务调试行为的“IncludeExceptionDetailInFaults”属性设置为 false,并使用无法正确验证的实体调用服务操作,服务中将引发以下异常:

Microsoft.Practices.Unity.ResolutionFailedException:依赖项解析失败,类型 =“Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl”,名称 =“WCF 异常屏蔽”。 异常发生时:解决时。 例外是:InvalidOperationException - ExceptionPolicyImpl 类型有多个长度为 2 的构造函数。无法消除歧义。

但如果我将 IncludeExceptionDetailInFaults 设置为 true,则会将验证错误返回给客户端。

有人知道我错过了什么吗?

【问题讨论】:

    标签: wcf enterprise-library


    【解决方案1】:

    看起来您正在尝试使用 Fluent API 方法配置 Ent Lib。当我尝试使用两个配置文件(web.config)和流利的 api 配置 Ent Lib 时,我遇到了类似的错误。如果是,您可以尝试删除配置文件变量并仅使用 fluent api。我发现这解决了我的错误。 告诉我进展如何。

    【讨论】:

    • 我正在尝试为 Old app .net 3.5 clr 2.0 appPoolEnt Lib 5.0 配置 Ent Lib 4.1对于带有两个配置文件 (web.config) 的 New app .net 4.5 clr 4.0 appPool ,我得到了同样的错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-22
    • 2022-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-22
    相关资源
    最近更新 更多