Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does .NET have a linker?

From Jon Skeet's blog:

What does the following comment mean?

    // The line below only works when linked rather than
    // referenced, as otherwise you need a cast.
    // The compiler treats it as if it both takes and
    // returns a dynamic value.
    string value = com.MakeMeDynamic(10); 

I understand what referencing an assembly is. You may reference it when compiling the program files either using the /ref: switch at the command line or you may add a static reference to the assembly in Visual Studio.

But how do you link to an assembly in .NET? Does he mean, load the assembly using Reflection (Assembly.LoadFile())? Or, the Win32 API LoadLibrary()? Or, does .NET have a linker that I have never heard of?

like image 771
Water Cooler v2 Avatar asked May 21 '10 12:05

Water Cooler v2


1 Answers

It's for COM Primary Interop Assemblies, basically. In .NET 4, you can either reference them as normal or "link" / "embed" them - in which case you end up with just the bits of the PIA that you're interested in embedded into your own assembly.

From the command line, this is the /link: option of the C# 4 compiler.

like image 199
Jon Skeet Avatar answered Oct 04 '22 22:10

Jon Skeet