问题使用“useLegacyV2RuntimeActivati​​onPolicy'和; supportedRuntime在应用程序中应用程序、问题、useLegacyV2RuntimeAct

2023-09-05 02:24:58 作者:在森林麋了鹿

我已经修改了几个不同的应用程序的config文件中是这样的:

I've modified a couple of different applications' .config file like this:

<startup useLegacyV2RuntimeActivationPolicy="true">
   <supportedRuntime version="v4.0"/>
</startup>  

当我这样做是为devenv.exe.config(VS 2005 - 不要问:)),一切工作的伟大 - 大部分的Visual Studio中的.NET 2.0,但我还是能利用定位的程序集。 .NET 4.0框架。

When I did this for devenv.exe.config (VS 2005 - don't ask :) ), things work great - most of the Visual Studio used .NET 2.0 but I was able to make use of an assembly targeting .NET 4.0 framework.

我试图做同样的事情,一个自定义的.exe,而这恰好是基于MS CAB(略有修改),并有WPF和WinForms内容的混合搭配。当我修改了这个应用程序的应用程序配置文件,我开始这个例外,有时在应用程序启动:

I tried to do the same thing for a custom .exe, which happens to be based on MS CAB (slightly modified) and has a hybrid mix of WPF and WinForms content. As soon as I modified this application's app config file, I started getting this exception, sometime during application startup:

撤消操作遇到一个方面是从什么在相应的设置操作应用于不同。可能的原因是,上下文设置线程上,而不是回复(撤消)。   System.InvalidOperationException:撤消操作遇到一个方面是从什么在相应的设置操作应用于不同。可能的原因是,上下文设置线程上,而不是回复(撤消)。

The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone). System.InvalidOperationException: The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone).

有一个大的长的堆栈跟踪,这并不在我的应用程序$ C $显示任何Ç直接(只是一堆MS组件)。

There's a big long stack trace that doesn't show anything in my application code directly (just a bunch of MS assemblies).

如果我修改应用程序的config文件,以这样的:

If I modify the application's .config file to this:

<startup useLegacyV2RuntimeActivationPolicy="true">
</startup>

IEI删除supportedRuntime元素,那么应用程序不会抛出该异常。但是,当我去我的code的地步,我尝试加载我的.NET 4集,如果失败,这样的:

i.e.I remove the supportedRuntime element, then the application doesn't throw this exception. But when I go to the point in my code where I try to load my .NET 4 assembly, if fails with this:

System.BadImageFormatException:无法加载文件或程序集或它的某一个依赖。这个组件由一运行时间比当前加载运行时更新的构建并不能装载。

System.BadImageFormatException: Could not load file or assembly '' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

我想这是预期。

我有两个问题:

1)任何想法,为什么我收到System.InvalidOperationException异常,当我修改这个应用程序的配置文件以包含supportedRuntime元素,加入.NET 4的支持和对我可以做些什么有什么建议?

1) Any idea why I'm getting the System.InvalidOperationException exception when I modify this application's configuration file to include the supportedRuntime element, adding .NET 4 support and any suggestions on what I can do about it?

2)如果回答是不知道为什么/不知道你可以做些什么,则有可能为我的.NET 3.5 SP1 code(C#),以提供有条件更细粒度的支持不转换我的整个应用程序的目标。NET 4,使用或不使用声明配置文件的方式添加一定组件(IES).NET 4运行时支持?在某些时候,我会转换成整个应用程序面向.NET 4,但在短期内,这是一项艰巨的任务,我希望一些短期解决方案/黑客攻击。

2) If the answer is "no idea why/don't know what you can do about it", then is possible for my .NET 3.5 SP1 code (C#) to provide more fine grain support for conditionally adding .NET 4 runtime support for a certain assembly(ies) without converting my entire application to target .NET 4, or without using the declarative config file approach? At some point I would convert the entire application to target .NET 4, but for the short term this is daunting task and I'm hope for some short term solution/hack.

非常感谢您的任何建议可以给你!

Thank you very much for any advice you can give!

推荐答案

我不知道你看到了VS2005什么行为,但它不应该是大部分的Visual Studio .NET使用的情况下, 2.0,但我还是能利用定位.NET 4.0框架的一个组件。这种配置应该引起家居中对V4运行过程。如果不是这种情况,我当然想知道它,因为它可能是一个错误。 (顺便说一句,我敢肯定,你意识到你是通过前滚VS2005到V4支持的情况外)。

I'm not sure exactly what behavior you're seeing for VS2005, but it shouldn't be the case that "most of the Visual Studio used .NET 2.0 but I was able to make use of an assembly targeting .NET 4.0 framework". That config should cause everything in the process to run on v4. If this is not the case, I'd certainly like to know about it because it's likely a bug. (BTW, I'm sure you realize that you're outside a supported scenario by rolling VS2005 forward to v4.)

至于无效操作异常,我的猜测是,你打了某种框架之间的不兼容的。我敢肯定,我们希望得到一个错误,以及。您可以在共享例外堆栈跟踪?

As to the invalid operation exception, my guess would be that you're hitting some kind of incompatibility between frameworks. I'm sure we'd like to get a bug on that as well. Can you share the stack trace at the exception?

至于采取增量升级方法......是不是真的有一个很好的答案。 CLR的自动支持在进程内的SxS激活的COM组件,因此,如果您的应用程序的方式,你可以提取模块,COM组件实现的,那么你可以利用这一点。的问题是,大多数的应用程序未这样写的,并简单地升级一切v4的是小于重新架构该应用的工作​​。

As far as taking an incremental upgrade approach... There is not really a good answer. The CLR supports in-proc SxS activation automatically for COM components, so if your app is implemented in a way where you can extract modules as COM components, then you could leverage that. The problem is that most apps are not written in this way, and simply upgrading everything to v4 is less work that re-architecting the app.

个别组件负载发生触发负荷运行。有没有在进程内的SxS激活正常的装配负荷。

Individual assembly loads occur in the runtime that triggered the load. There's no in-proc SxS activation for normal assembly loads.