3

I'm trying out the new Spring CodeConfig for .NET but have tons of trouble with it.

I installed the NuGet package Spring.CodeConfig into an existing .NET 4 project, but have had nothing but trouble with it.

The ScanAllAssemblies method throws a ReflectionTypeLoadException when I run this code:

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

This happens even if I have defined no configuration class, but it also happens if I create a configuration class.

The LoaderExceptions property contains a single exception with this message:

Could not load file or assembly 'System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. Invalid pointer (Exception from HRESULT: 0x80004003 (E_POINTER))

I've tried adding an assembly redirect from version 1.0.3300.0 of System to version 4.0.0.0, which is the one that's referenced in my project, but this doesn't work.

How can I resolve this issue?


As requested, here are the references from the project in question:

  • mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  • Ploeh.Samples.MenuModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
  • Spring.Aop, Version=1.3.1.40711, Culture=neutral, PublicKeyToken=65e474d141e25e07
  • Spring.Core, Version=1.3.1.20711, Culture=neutral, PublicKeyToken=65e474d141e25e07
  • Spring.Core, Version=1.3.1.40711, Culture=neutral, PublicKeyToken=65e474d141e25e07
  • Spring.Core.Configuration, Version=1.0.0.4111, Culture=neutral, PublicKeyToken=65e474d141e25e07
  • System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  • System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  • System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  • System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  • xunit, Version=1.7.0.1540, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c

Since the second reference is a project reference, I'm also listing its dependencies:

  • mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  • System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

I also have these binding redirects in my App.config - in case it matters:

<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>

However, both were attempts to fix problems with CodeConfig. Removing them doesn't help...

4

1 回答 1

4

经过一番调查,我们发现这是 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-04-09T13:28:58.437 回答