简体   繁体   English

.NET外部DLL参考检查

[英].NET external dll reference check

In .NET when an exe/dll refers to external dlls, how is that information encoded into the exe/dll? 在.NET中,当exe / dll引用外部dll时,该信息如何编码到exe / dll中? At what time does the validity of the dll is checked? 在什么时候检查dll的有效性? When is the signing info checked? 签名信息何时被检查?

Edit: This is at runtime 编辑:这是在运行时

Run ildasm.exe from the Visual Studio Command Prompt and open an arbitrary .NET exe or dll file. 从Visual Studio命令提示符运行ildasm.exe并打开任意.NET exe或DLL文件。 Double-click the Manifest and you'll for example see: 双击Manifest,您将看到:

.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) 
  .ver 2:0:0:0
}

Which tells you that the assembly you are looking at has a dependency on another assembly called mscorlib. 这告诉您正在查看的程序集依赖于另一个名为mscorlib的程序集。 Or in other words, the metadata of the assembly contains a reference to all the DLLs it has a dependency on. 或者换句话说,程序集的元数据包含对它依赖的所有DLL的引用。 Look at the other .assembly directives to see the other dependencies, I picked one that you'll always find back. 查看其他.assembly指令以查看其他依赖项,我选择了一个你总能找到的依赖项。

The .ver entry is important, that says which [AssemblyVersion] of mscorlib is needed. .ver条目很重要,它说明需要mscorlib的[AssemblyVersion]。 Version 2.0.0.0 in my case, could be 4.0.0.0 in your case. 在我的情况下,版本2.0.0.0在您的情况下可能是4.0.0.0。 The two most common versions used for that particular assembly. 用于该特定组件的两个最常见的版本。 Anything is possible for a custom assembly, the [AssemblyVersion] attribute is Very Important. 任何可能的自定义程序集,[AssemblyVersion]属性是非常重要的。

The .publickeytoken is the part of the validity check, it helps to verify the strong name of the assembly at runtime. .publickeytoken是有效性检查的一部分,它有助于在运行时验证程序集的强名称。 It happens when the assembly is loaded and strong name verification is enabled. 加载程序集并启用强名称验证时会发生这种情况。 It is only enabled when the assembly is retrieved from an untrusted location. 仅在从不受信任的位置检索程序集时才启用它。

Assemblies are loaded by the jitter whenever it needs to compiled code that uses a type that is defined in another assembly. 只要需要使用在另一个程序集中定义的类型的已编译代码,程序集就会被抖动加载。 It is the CLR's job to find that assembly from the info provided in the above .assembly reference. CLR的工作是从上面的.assembly参考中提供的信息中找到该程序集。 Do note how that info doesn't store the path to the file. 请注意该信息如何不存储文件的路径 The way the CLR locates that file is a long story by itself, well covered by the MSDN Library article about it. CLR定位该文件的方式本身就是一个很长的故事,MSDN Library关于它的文章很好地介绍了它。

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

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