简体   繁体   English

在.NET 4上运行.NET 3.5应用程序时崩溃

[英]Crash when running a .NET 3.5 app on .NET 4

Our application is built using WinForms on .NET 3.5 我们的应用程序是使用.NET 3.5上的WinForms构建的

This was tested specifically on Windows XP, although i am not sure whether it is OS related. 尽管我不确定它是否与操作系统相关,但已在Windows XP上对其进行了专门测试。

Whenever i run it on a machine with .NET 4 only, it will crash, saying that it cannot find the .NET assemblies versioned 3.5. 每当我在仅具有.NET 4的计算机上运行它时,它都会崩溃,并表示它找不到版本为3.5的.NET程序集。

I am wondering why this does not happen automatically. 我想知道为什么这种情况不会自动发生。 For example, some 3rd party libraries install a policy of some sort, that when a newer version is installed, it will be used, even if your application was compiled against an older version. 例如,某些第三方库安装了某种策略,即使安装了较旧版本的应用程序,当安装了较新版本时,也会使用该策略。

UPDATE: The exact error message is: 更新:确切的错误消息是:

"Unable to find a version of the runtime to run this application". “无法找到运行该应用程序的运行时版本”。

My questions are: 我的问题是:

  1. Why is this not the same with the .NET framework? 为什么与.NET框架不一样?
  2. The solution is to add the element in the configuration file? 解决的方法是在配置文件中添加元素? Any other solutions? 还有其他解决方案吗?

In general, that should not be the case: 通常,情况并非如此:

http://msdn.microsoft.com/en-us/library/ff602939.aspx http://msdn.microsoft.com/en-us/library/ff602939.aspx

Backward compatibility means that an application developed for a particular version of a platform will run on later versions of that platform. 向后兼容意味着为平台的特定版本开发的应用程序将在该平台的更高版本上运行。 The .NET Framework tries to maximize backward compatibility: Source code written for one version of the .NET Framework should compile on later versions of the .NET Framework, and binaries that run on one version of the .NET Framework should behave identically on later versions of the .NET Framework. .NET Framework试图最大化向后兼容性:为一个版本的.NET Framework编写的源代码应在更高版本的.NET Framework上编译,并且在一个版本.NET Framework上运行的二进制文件在更高版本上的行为应相同.NET Framework。

... ...

The .NET Framework 4 is backward-compatible with applications that were built with the .NET Framework versions 1.1, 2.0, 3.0, and 3.5. .NET Framework 4与使用.NET Framework 1.1、2.0、3.0和3.5版构建的应用程序向后兼容。 In other words, applications and components built with previous versions of the .NET Framework will work on the .NET Framework 4. 换句话说,使用.NET Framework早期版本构建的应用程序和组件将在.NET Framework 4上运行。

SUGGESTIONS: 建议:

1) Read these links: 1)阅读以下链接:

2) See if you can reproduce the problem with a minimal .Net 3.5 Winforms app 2)看看是否可以使用最小的.Net 3.5 Winforms应用程序重现该问题

3) Cut/paste the exact error message, and any relevant code (eg from your standalone app) 3)剪切/粘贴确切的错误消息以及任何相关代码(例如,从您的独立应用程序获取)

4) Failing all else, consider adding <startup useLegacyV2RuntimeActivationPolicy="true" > to your CLR startup configuration. 4)如果其他所有操作均失败,请考虑将<startup useLegacyV2RuntimeActivationPolicy="true" >到CLR启动配置中。 I would not recommend this as anything but a temporary workaround: 除了临时解决方法外,我建议这样做:

.NET 4.0 introduce new CLR. .NET 4.0引入了新的CLR。 So basicly having 4.0 doesn't help much in running 3.5 apps. 因此,基本上拥有4.0对运行3.5个应用程序无济于事。 It has been already mentioned here 已经在这里提到了

If your computer has no .NET 3.5 installed there is no CLR to start for your app. 如果您的计算机未安装.NET 3.5,则不会为您的应用启动CLR。 .NET 4.0 is not automatically used for your app because of potential compatibility issues. 由于潜在的兼容性问题,.NET 4.0不会自动用于您的应用程序。 First test that your app does run with .NET 4.0 and then add this section to your app.config to tell the CLR to prefer running .NET 4.0 if present. 首先测试您的应用程序确实可以在.NET 4.0上运行,然后将本节添加到app.config中,以告知CLR首选运行.NET 4.0(如果存在)。

<configuration>
   <startup>
      <supportedRuntime version="v4.0.30319"/>
   </startup>
</configuration>

If .NET 4 is not present as fallback the CLR version against which you application was compiled against is used as fallback. 如果.NET 4不作为后备版本,则将应用程序所针对的CLR版本用作后备版本。 If all fails you get the message "Unable to find a version of the runtime to run this application". 如果全部失败,您将收到消息“无法找到运行该应用程序的运行时版本”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM