2

我有一个自托管的 WCF 服务,我使用 Castle Windsor 作为 DI 容器。我得到了这个例外:

System.TypeLoadException occurred
  _HResult=-2146233054
  _message=GenericArguments[0], 'System.ServiceModel.ServiceHostBase', on 
           'Castle.Facilities.WcfIntegration.IChannelFactoryBuilder`1[M]' 
           violates the constraint of type parameter 'M'.
  HResult=-2146233054
  IsTransient=false
  Message=GenericArguments[0], 'System.ServiceModel.ServiceHostBase', on 
          'Castle.Facilities.WcfIntegration.IChannelFactoryBuilder`1[M]' 
          violates the constraint of type parameter 'M'.
  ResourceId=0
  TypeName=""
  InnerException: 

Castle 容器的配置如下所示:

Container = new WindsorContainer()
            .AddFacility<WcfFacility>();

Container.Register(
            Component.For<IReportsService>().ImplementedBy<ReportsService>().LifestylePerWcfOperation(),
            Component.For<IAdminServices>().ImplementedBy<AdminServices>().LifestylePerWcfOperation(), etc...

我通过以下代码创建 WCF 服务:

host = new DefaultServiceHostFactory().CreateServiceHost(typeof(IAdminServices).AssemblyQualifiedName, new Uri[0]);
host.Open();

它工作正常,但如果我在调试中运行选中“抛出异常时中断”选项调试器总是在线停止

host = new DefaultServiceHostFactory().CreateServiceHost(typeof(IAdminServices).AssemblyQualifiedName, new Uri[0]);

我向我展示了上面列出的异常。

我是否以错误的方式将 Castle 与 WCF 一起使用?我可以避免这个例外吗?

编辑:

该问题仅出现在 Visual Studio 2013 中,在 2012 中很好。

我使用这些版本的城堡:

城堡核心 - 3.3.0

城堡 WcfIntegrationFacility - 3.3.0

温莎城堡 - 3.3.0

4

1 回答 1

1

问题是由 Type.MakeGenericType 引发的未记录异常引起的。在非托管代码中引发异常。Visual Studio 2012 和 2013 之间没有区别。差异是由调试设置引起的(在 VS 2012 中启用了“仅我的代码”)。更多信息可以在这里找到:

https://github.com/castleproject/Windsor/issues/69#issuecomment-68518061

于 2015-01-02T14:51:03.860 回答