473,770 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.c tor() ) 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 2577
>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.LoadFr om method).

If the assembly you referenced is a strong named, CLR will resolve all the
strong name information(tha t 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-sideexecutionto p.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.Class 1 obj=new testclass.Class 1();
obj.testmethod( );
}
//Original dll assembly
public class Class1
{
public Class1()
{
}

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

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

public void testmethod2()
{
Console.WriteLi ne("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.(Actu ally, 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
1263
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 project? Are there any good articles that describe interfaces from a good functional/operational/Visual Studio .NET point of view? I am working on a multi-project solution whose references are a combination of project references and file references....
1
15341
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 Assembly.CreateInstance to create an object that implements an interface it cannot cast to the appropriate interface type before returning. e.g. ISubmit lo_MessagingObject=null; string
0
1273
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 assembly which now has multiple server controls - hence multiple class declarations. When I use this server menu control on an aspx page and run the application I get the following error
3
286
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 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
3
7841
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 modified on a per project basis) as the 'program.cs' file (the only *.cs file). I keep getting 'Main() not defined error' even though it was defined via the DLL reference in the project.
18
2400
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 happen that I forget one or the other .dll. Since my app depends on a whole bunch of .dll it would be great, if the app could tell me which assemblies are missing instead of not starting at all.
1
2065
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 main.c Linker Error: Undefined symbol VADDR in module asm.asm In my asm.asm file I've got: DOSSEG
1
1756
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 deploy it on another computer, I get an error with the description below: System.IO.FileLoadException: Could not load file or assembly 'GSLWrapper, Version=1.0.2903.28643, Culture=neutral, PublicKeyToken=null' or one of its dependencies. This...
13
2156
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 function? what kind of privilege level would be required to execute a program with assembly in it? how would I denote that the following code is assembly and thus shouldn't be checked for syntax errors? ------------------------------ Robert Cloud...
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.