【问题标题】:Spring CodeConfig ScanAllAssemblies throws a ReflectionTypeLoadExceptionSpring CodeConfig ScanAllAssemblies 抛出 ReflectionTypeLoadException
【发布时间】:2011-08-01 09:58:06
【问题描述】:

我正在尝试用于 .NET 的新 Spring CodeConfig,但遇到了很多麻烦。

我将 NuGet 包 Spring.CodeConfig 安装到现有的 .NET 4 项目中,但遇到了麻烦。

当我运行此代码时,ScanAllAssemblies 方法会引发 ReflectionTypeLoadException:

var context = new CodeConfigApplicationContext();
context.ScanAllAssemblies();
context.Refresh();

即使我没有定义配置类也会发生这种情况,但如果我创建了配置类也会发生这种情况。

LoaderExceptions 属性包含一个带有此消息的异常:

无法加载文件或程序集“系统,版本=1.0.3300.0,文化=中性,PublicKeyToken=b77a5c561934e089”或其依赖项之一。无效指针(HRESULT 异常:0x80004003 (E_POINTER))

我尝试添加从 System 1.0.3300.0 版本到版本 4.0.0.0 的程序集重定向,这是我的项目中引用的版本,但这不起作用。

我该如何解决这个问题?


根据要求,以下是相关项目的参考资料:

  • mscorlib,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089
  • Ploeh.Samples.MenuModel,版本=1.0.0.0,文化=中性,PublicKeyToken=null
  • Spring.Aop,版本=1.3.1.40711,文化=中性,PublicKeyToken=65e474d141e25e07
  • Spring.Core,版本=1.3.1.20711,文化=中性,PublicKeyToken=65e474d141e25e07
  • Spring.Core,版本=1.3.1.40711,文化=中性,PublicKeyToken=65e474d141e25e07
  • Spring.Core.Configuration,版本=1.0.0.4111,文化=中性,PublicKeyToken=65e474d141e25e07
  • 系统,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089
  • System.Core,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089
  • System.Xml,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089
  • System.Xml.Linq,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089
  • xunit,版本=1.7.0.1540,文化=中性,PublicKeyToken=8d05b1bb7a6fdb6c

由于第二个引用是项目引用,我也列出了它的依赖关系:

  • mscorlib,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089
  • System.Core,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089

我的 App.config 中也有这些绑定重定向 - 以防万一:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Spring.Core" publicKeyToken="65e474d141e25e07" culture="neutral" />
    <bindingRedirect oldVersion="1.3.1.20711" newVersion="1.3.1.40711" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System" publicKeyToken="b77a5c561934e089" culture="neutral" />
    <bindingRedirect oldVersion="1.0.3300.0" newVersion="4.0.0.0" />
  </dependentAssembly>
</assemblyBinding>

但是,两者都试图解决 CodeConfig 的问题。删除它们没有帮助...

【问题讨论】:

    标签: c# spring.net spring.codeconfig


    【解决方案1】:

    经过一番调查,我们确定这是 4.0 CLR 下的 ReflectionOnlyLoad API 存在的问题。

    CodeConfig 程序集扫描在 2.0 CLR 下工作,但显然尽管 .NET 3.5 和 .NET 4.0 之间的 ReflectionOnlyLoad API 没有明显变化,但 ReflectionOnlyLoad 处理依赖程序集的方式似乎存在行为差异(或者更准确地说,我们在 .NET 4.0 下以编程方式解析 ReflectionOnlyLoad API 的类型)。

    Spring.NET 团队现在正在开发 CodeConfig (1.0.1) 的快速更新版本,该版本应能正确解决此问题并允许其在 .NET 4.0 下成功使用。感谢您提请我们注意!

    【讨论】:

      猜你喜欢
      • 2011-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-09
      • 2019-05-11
      • 2014-04-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多