为什么一台机器使用.NET 4安装在其上不能运行一个exe,有​​针对性.NET 4.5,而如果他们使用相同的CLR版本?一台、针对性、其上、机器

2023-09-02 01:59:19 作者:Care(在乎)

在公共语言运行库(CLR)微软网页,它说,4和4.5两个.Net框架使用CLR版本4。

In Common Language Runtime (CLR) Microsoft page, it says that both .Net Framework 4 and 4.5 uses the CLR version 4.

然而,在此页面( .NET Framework版本和依赖)将其写入.NET Framework版本4.5包含CLR 4的升级版

However in this page (.NET Framework Versions and Dependencies) it writes '.Net Framework version 4.5 Included an updated version of CLR 4'

还写道:

是面向.NET Framework 4.5.1的可执行文件将被从只有安装了.NET Framework 4.5的计算机上运行受阻,用户将被提示安装.NET Framework 4.5。 1。此外,.NET框架4.5.1组件不应该叫从.NET框架4.5的应用程序。的

问:如果4所有.NET Framework版本4.5和4.5.1运行管理code在同一个CLR版本是4,为什么我不能运行一个可执行文件,有针对性的.Net框架4.5的机器,只有.NET 4.0中安装?

QUESTION: If all Net Framework version 4 and 4.5 and 4.5.1 runs the managed code on the same CLR version that is 4, why I cannot run an executable that targeted .Net framework 4.5 on a machine that has only .Net 4.0 installed?

(不要编译器产生IL这对于到底CLR版本4,无论你有针对性的.NET框架4或4.5或4.5.1?)

(Do not the compilers produce an IL that is for CLR version 4 in the end regardless you targeted .NET framework 4 or 4.5 or 4.5.1?)

推荐答案

是的,CLR版本是一样的,还是v4.0.30319。什么打破了高度向后破路是.NET框架类库。通过整合支持的WinRT(存储应用程序)到框架驱动的变化。几种类型从一个程序集移动到另一个,最明显的是ExtensionAttribute和ICommand的。对于需要在移动设备上的小.NET实现是有助的。 System.Core程序和presentationFramework不小。

Yes, the CLR version is the same, still v4.0.30319. What broke in a highly backwards-breaking way were the .NET Framework class libraries. Changes that were driven by integrating support for WinRT (Store apps) into the framework. Several types were moved from one assembly to another, the most visible ones are ExtensionAttribute and ICommand. The need for small .NET implementations on mobile devices was instrumental. System.Core and PresentationFramework are not small.

这是相当一个大问题,一个类型声明中是一个.NET类型的类型的身份的部分组件。或者换一种说法,即具有相同的命名空间名称和类型名称的.NET类型是永远不会有一个类型与来自其他程序集相同的全名兼容。

That's rather a big deal, the assembly that a type is declared in is part of the type identity of a .NET type. Or to put it another way, a .NET type that has the same namespace name and type name is never compatible with a type with the same full name that came from another assembly.

这是可能的,在一切都因为创新,开始在.NET 4.0中。开始于[TypeForwardedTo]属性,是什么是用来移动一个类型。而特制的引用程序集在C: Program Files文件引用程序集。特别之处在于它们只包含元数据,并且不直接匹配安装在GAC的实际组件,你的程序会在运行时使用。

That this was possible at all was due to innovations that started in .NET 4.0. Starting with the [TypeForwardedTo] attribute which is what is used to move a type. And the specially crafted reference assemblies in c:program filesreference assemblies. Special in that they only contain metadata and are not a direct match with the actual assemblies installed in the GAC that your program will use at runtime.

这不出差错,有时在一个非常难以诊断的方法,诱发使用了错误的引用程序集。不幸的是微软保留了传统的引用程序集在C: WINDOWS microsoft.net 框架各地。使用它们的项目在pretty的悲惨的方式失败。

This does go wrong sometimes in a very hard to diagnose ways, induced by using the wrong reference assemblies. Unfortunately Microsoft kept the traditional reference assemblies in c:windowsmicrosoft.netframework around. Projects that use them fail in a pretty miserable way.

所以这只是不能工作,一个程序,面向.NET 4.5的就找错4.0 GAC组件的类型,如ExtensionAttribute和ICommand的。并配有完全undiagnosable TypeLoadException失败。因此,[TargetFramework]属性检查第一至无法尽早运行程序的企图。

So this just can't work, a program that targets .NET 4.5 will look in the wrong 4.0 GAC assemblies for types like ExtensionAttribute and ICommand. And fail with a utterly undiagnosable TypeLoadException. Accordingly, the [TargetFramework] attribute is checked first to fail the attempt to run the program as early as possible.

 
精彩推荐