【问题标题】:Castle Windsor WCF and System.TypeLoadException' occurred in mscorlib.dllCastle Windsor WCF 和 System.TypeLoadException' 发生在 mscorlib.dll 中
【发布时间】:2015-01-02 22:51:03
【问题描述】:

我有一个自托管的 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:

城堡核心 - 3.3.0

城堡 WcfIntegrationFacility - 3.3.0

温莎城堡 - 3.3.0

【问题讨论】:

    标签: .net wcf castle-windsor castle wcffacility


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多