问题描述
我有一个使用 System.Runtime.Serialization
组装项目。我现在用的类型的DataContractSerializer
从该程序集,但我有一个问题。有两个组件:
I have a project that uses System.Runtime.Serialization
assembly. I am using the type DataContractSerializer
from that assembly, but I have a problem.There are two assemblies:
C:\ Program Files文件(x86)的\参考大会\微软\ Framework.NETFramework \ V4.0 \ System.Runtime.Serialization.dll
C:\ WINDOWS \ Microsoft.net \框架\ v4.0.30319 \ System.Runtime.Serialization.dll
C:\Windows\Microsoft.net\Framework\v4.0.30319\System.Runtime.Serialization.dll
他们都具有相同的版本 - v4.0.30319。第一个有429KB的大小,而第二个1037kb。我用反射镜看到类的列表,第一个没有我需要的类( DataContractSerializerSettings
)。然而,第二个确实有它
Both of them have the same version - v4.0.30319. The first one have 429kb size, and the second one 1037kb. I used reflector to see the list of classes, and the first one doesn't have the class that I need (DataContractSerializerSettings
). However, the second one does have it.
为什么有该程序集的规模和班一些大的区别呢?会不会是好的,如果我用,而不是第一个,第二个,?
Why are there some big difference in size and classes for that assembly? Will it be ok, if I use the second one, instead of the first?
推荐答案
.NET 4.0版本的方式做出框架基准组件做了很大的改变。 previously,参考组件是运行时组件的简单复制,一个存储在GAC中。然而,这引起了一些棘手的问题。值得注意的是 WaitHandle.WaitOne(INT)
过载,它被添加在.NET 2.0 Service Pack 2更新(又名.NET 3.5)。程序员用它没有注意到,这是一个的添加的方法,在mscorlib程序集的版本号仍然是2.0.0.0。但后来发现,在.NET 2.0未打补丁的版本上运行时,他们的计划失败了。非常讨厌KABOOM,没有的MissingMethodException一丝为什么这样一个共同的方法可能会丢失。
.NET version 4.0 made a big change in the way framework reference assemblies are done. Previously, the reference assembly was a simple copy of the runtime assembly, the one stored in the GAC. That however caused some painful problems. Notable is the WaitHandle.WaitOne(int)
overload, it was added in the .NET 2.0 Service Pack 2 update (aka .NET 3.5). Programmers used it without noticing that it was an added method, the mscorlib assembly version number was still 2.0.0.0. But then discovered their program failed when running on an unpatched version of .NET 2.0. Very nasty kaboom, MissingMethodException without a hint why such a common method could be missing.
要prevent这种断裂,那么.NET 4.0的参考组件分开,在为%ProgramFiles%\参考大会目录中你发现了。他们是特殊的组件,它们只包含了所有的IL剥离出的元数据。这就是为什么大会是如此小的多。
To prevent this kind of breakage, the .NET 4.0 reference assemblies are kept separate, in the "%programfiles%\Reference Assemblies" directory as you found out. And they are special assemblies, they only contain the metadata with all the IL stripped out. Which is why the assembly is so much smaller.
微软现在可以提高.NET 4 code和增加公共类和方法,而不会造成这种断裂。而这样做大汗,更新4.01,4.02,自原来的4.0版本4.03已经发货。
Microsoft now can improve the .NET 4 code and add public classes and methods without causing this kind of breakage. And have done so profusely, updates 4.01, 4.02 and 4.03 have shipped since the original 4.0 release.
您有与 DataContractSerializerSetting
类故障的原因是这样容易解释,它只是不会出现在参考组装。它得到了补充,很可能在这些增量更新之一。你不应该尝试,你的程序将打破一台机器,没有更新。你应该等到.NET 4.5,即把它添加到引用程序集的版本。您可以调用DLL地狱,如果你真的想。
The reason you are having trouble with the DataContractSerializerSetting
class is thus easily explained, it just doesn't appear in the reference assembly. It got added, probably in one of those incremental updates. And you should not try, your program will break on a machine that doesn't have the update. You should wait until .NET 4.5, the version that added it to the reference assembly. You can invoke DLL Hell if you really want to.
这篇关于引用程序集文件夹,不同的组件具有相同版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!