views:

165

answers:

1

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?

+9  A: 

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.

Jon Skeet
Thanks, Jon. I should've completed reading the full article of yours that I linked to, before asking this question. I just finished reading it and a couple of other articles on the "No PIA" feature.So, is the /link: attribute a command-line equivalent of setting the "Embed Interop Types" property of the assembly reference to True in Visual Studio 2010? (http://thedotnethub.blogspot.com/2009/11/clr4-no-pia.html)Also, is the /link: option a new one that's been introduced in C# 4.0?
Water Cooler v2
@Water: Yes, that's the equivalent, and yes it's new to .NET 4 and C# 4.
Jon Skeet
Very many thanks, Jon. BTW, I am reading the first edition your book "C# in Depth" and am loving every bit of it.
Water Cooler v2
@Water: Glad to hear it - I'll be "done" with the second edition eventually :)
Jon Skeet
Yes, Jon. I've been following that one, too, closely.
Water Cooler v2