473,378 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Assembly linking

Suppose an assembly "Main" is using class "A" from another Assembly "Dep" as
follows :

A a = new A();
a.MethodOne();

At what time is the call to MethodOne linked to the actual MSIL (method
body) of the method? Does this occur when "Main" is build or does it happen
when main is loaded and Jitted? Also is the linking achieved by the full
method name( this is what is seen in the IL generated by ILDASM : e.g : call
System.String.ctor() ) or is it linked using a fixed number ( say its
ordinal in the class function table).

The reason I am asking this is what will happen if I add another method
"MethodTwo" to class "A" without changing the version of the assembly "Dep".
Will the "Main" assembly continue to run without the need to recompile?

If so, this should suggest that at least some part of the linking is done
during load-time.

Any explanations, doc references, online article references would be
appreciated.

Regards
Atul
Jul 21 '05 #1
3 2528
>At what time is the call to MethodOne linked to the actual MSIL (method
body) of the method? Does this occur when "Main" is build or does it happen
when main is loaded and Jitted?
Depends on what you mean by "linked". At compile time there's enough
information stored in the Main assembly to locate MethodOne in the A
class in the Dep assembly.

Also is the linking achieved by the full
method name( this is what is seen in the IL generated by ILDASM : e.g : call
System.String.ctor() ) or is it linked using a fixed number ( say its
ordinal in the class function table).
By name and signature, no magic numbers.

The reason I am asking this is what will happen if I add another method
"MethodTwo" to class "A" without changing the version of the assembly "Dep".
Will the "Main" assembly continue to run without the need to recompile?
Yes.

If so, this should suggest that at least some part of the linking is done
during load-time.


Well yes, the actual method to call is looked up by name at runtime.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #2
Hi Atul,

Thanks for your post!!

Based on my understanding, you want to get some detailed information about
how CLR resolves used method from a referenced assembly.

Normally, .Net uses dynamically loading technology in Win32 world. That is
the referenced code is not embeded in the exe's file. For .Net exe
assembly, it resolves the assembly reference, type reference, method
reference at load time(this only applies when you are not doing explicit
loading with Assembly.Load or Assembly.LoadFrom method).

If the assembly you referenced is a strong named, CLR will resolve all the
strong name information(that is all of assembly file name, version,
cultrual and PublicKeyToken), so if you replace a new compiled version of
the assembly in the CLR probing path, CLR will still load the original
assembly. This is called Side-by-Side execution in .Net, for more
information please refer to:
"Side-by-Side Execution"
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconside-by-sideexecutiontop.asp

For not strangly named assembly, CLR will ignore the version information,
only use the assembly file name for loading, so it may load the new version
assembly. Below is a little test for this:
//Exe assembly
static void Main(string[] args)
{
testclass.Class1 obj=new testclass.Class1();
obj.testmethod();
}
//Original dll assembly
public class Class1
{
public Class1()
{
}

public void testmethod()
{
Console.WriteLine("abc");
}
}
//new version dll
public class Class1
{
public Class1()
{
}

public void testmethod()
{
Console.WriteLine("abc2");
}

public void testmethod2()
{
Console.WriteLine("def");
}
}
If I replace the original dll with the new version, my exe file execution
will output "abc2" without any problem.

For more information, please refer to the article in "Suzanne Cook's .NET
CLR Loader" blog:
"Assembly Identity"
http://blogs.msdn.com/suzcook/archiv.../21/57232.aspx
"Avoid Partial Binds"
http://blogs.msdn.com/suzcook/archiv.../30/57159.aspx

Actually, internally, CLR uses the metadata and manifest information in the
assembly for the Loading process, for example, there is AssemblyRef field
in the assembly manifest, and the CLR will use AssemblyRef for the
referenced assembly probing and loading information. You can find more
detailed information in "Jeffrey Richter"'s wonderful book "Applied
Microsoft .Net Framework Programming", especially, there is a section named
"How the Rntime Resolves Type References" with a picture shows us how CLR
performance the type resolution.

So for your question, the answer is once the refered assembly's public
interface(such as type name, public methods name, public properties name
,etc), there is no need for the exe to do re-buiding. Also, the backward
compatibility is important, unless you are using side-by-side
execution.(Actually, side-by-side execution is the key component in .Net
that eliminate DLL Hell)

Currently, there is few official document about CLR Loader internal, I
think "Suzanne Cook's .NET CLR Loader" blog should be an invaluable
resource for this topic(she is the .Net CLR team SDE focused on CLR
Loader), please refer to:
http://blogs.msdn.com/suzcook
================================================== ==========================
========
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #3
Hi Atul,

Does my reply make sense to you? If you still have any concern, please feel
free to feedback, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hazzard | last post by:
If I have two assemblies in a VSNET project and create an interface, does the interface have to reside in the assembly whose class methods it describes? How do I reference interfaces in the...
1
by: John Jenkins | last post by:
Hi, I have a fairly simeple question. What are the differences between Assembly.CreateInstance and System.Activator.CreateInstance? I had read that one maps to the other, however when I use...
0
by: Sanjay Tibrewal | last post by:
Hello, I am trying out a piece of code I downloaded from a link on msdn site. It's a server menu generating control that I tried to add to my custom control assembly. I was able to compile the...
3
by: Atul Godbole | last post by:
Suppose an assembly "Main" is using class "A" from another Assembly "Dep" as follows : A a = new A(); a.MethodOne(); At what time is the call to MethodOne linked to the actual MSIL (method...
3
by: Shawnk | last post by:
I use two classes to manage the Main() command line (and alot of other stuff) for my prototyping environment. I tryed putting the MainClass in a DLL and just having the other class (which gets...
18
by: Rainer Queck | last post by:
Hello NG, I realized, that my application won't start, if a referenced assembly is missing. Basically this is understandable, but since I destribute my applictaion without a setup, it can...
1
by: Andrew Wan | last post by:
I am having problems linking an assembly object with my C object files. Am getting: Linker Warning: DOSSEG directive ignored in module asm.asm Linker Error: Undefined symbol _ASMClsV in module...
1
by: Benny | last post by:
I have built a wrapper class as a dll in Visual Studio 2005 using Visual C++ .Net. When I include the dll in another project, Project B, on my machine, it works. When I package Project B and...
13
by: Robert Cloud | last post by:
Is it possible to include assembly language routines in C if I'm using a compiler which has an assembler such as gcc? could I include them in a main function or would I have to write a seperate...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.