获取“ComponentActivatorException”使用 .net 2.0 组件从 .net 4.0 应用程序使用 Castle Windsor
我有一个正在 VS2010 中开发的应用程序,并通过配置文件使用 Castle-Windsor IoC。
我正在注册的组件之一(也是在 VS2010 中开发的)引用了 .net 2.0 组件 (LeadTools),因此无法重新编译 2.0 项目。包装组件的注册完成后,会引发“ComponentActivatorException”,其中包装“System.TypeInitializationException”,而“System.TypeInitializationException”又包装“System.IO.FileLoadException”,并显示消息“混合模式程序集是针对版本‘v2’构建的” .0.50727' 的运行时,如果没有附加配置信息,则无法在 4.0 运行时加载。”
我已将运行时声明添加到应用程序的配置文件中,如下所示:
<!-- useLegacyV2RuntimeActivationPolicy is needed for LEADTools-->
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<supportedRuntime version="v2.0.50727" />
</startup>
如果包装组件未在 Windsor 中注册,则效果很好,但是,否则它似乎会忽略指令。
谢谢!
I have an application which is being developed in VS2010, and makes use of the Castle-Windsor IoC, through a configuration file.
One of the components I am registering, also developed in VS2010, references a .net 2.0 component (LeadTools), so recompiling the 2.0 project isn't an option. When the wrapping component's registration is done, a "ComponentActivatorException" is raised, which wraps a "System.TypeInitializationException", which in turn wraps a "System.IO.FileLoadException" with a message of "Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information."
I have added the runtime declaration to the application's configuration file, as so:
<!-- useLegacyV2RuntimeActivationPolicy is needed for LEADTools-->
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<supportedRuntime version="v2.0.50727" />
</startup>
This works fine if the wrapping component isn't registered in Windsor, however, it does appear to disregard the directives otherwise.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您正在使用通过 XML 进行注册?
如果您在代码中注册组件会发生什么?
您可以尝试重现该问题而不出现错误吗?
call
Type.GetType(".net 2.0 程序集中类型的程序集限定名称");
I assume you're using registration via XML?
What happens if you register the component in code?
Can you try to reproduce the issue without error?
call
Type.GetType("assembly qualified name of the type from .net 2.0 assembly");
该问题是由于在配置文件中使用“define”和“if”造成的,根据 MicroKernel 文档。从 App.Config 文件中删除所有这些元素就可以实例化组件,无论它们是否已在 Windsor 容器中注册。
The problem was due to using "define"s and "if"s within the configuration file, per the MicroKernel documentation. Removing all of those elements from the App.Config file allowed the components to be instantiated, whether or not they were registered in the Windsor container.