Castle Windsor WCF和System.TypeLoadException'发生在mscorlib.dll中

时间:2014-08-07 12:23:20

标签: .net wcf castle-windsor castle wcffacility

我有一个自托管的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年就可以了。

我使用这些版本的Castle:

Castle Core - 3.3.0

Castle WcfIntegrationFacility - 3.3.0

Castle Windsor - 3.3.0

1 个答案:

答案 0 :(得分:1)

问题是由Type.MakeGenericType抛出的无证异常引起的。非托管代码中抛出异常。 Visual Studio 2012和2013之间没有区别。差异是由调试设置引起的(在VS 2012中启用“Just My Code”)。更多信息可以在这里找到:

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