tvr
tvr

Reputation: 4575

.NET external dll reference check

In .NET when an exe/dll refers to external dlls, how is that information encoded into the exe/dll? At what time does the validity of the dll is checked? When is the signing info checked?

Edit: This is at runtime

Upvotes: 3

Views: 1341

Answers (1)

Hans Passant
Hans Passant

Reputation: 941317

Run ildasm.exe from the Visual Studio Command Prompt and open an arbitrary .NET exe or dll file. Double-click the Manifest and you'll for example see:

.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. Or in other words, the metadata of the assembly contains a reference to all the DLLs it has a dependency on. Look at the other .assembly directives to see the other dependencies, I picked one that you'll always find back.

The .ver entry is important, that says which [AssemblyVersion] of mscorlib is needed. Version 2.0.0.0 in my case, could be 4.0.0.0 in your case. The two most common versions used for that particular assembly. Anything is possible for a custom assembly, the [AssemblyVersion] attribute is Very Important.

The .publickeytoken is the part of the validity check, it helps to verify the strong name of the assembly at runtime. 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. 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.

Upvotes: 6

Related Questions