473,396 Members | 1,940 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,396 software developers and data experts.

.NET Assemblies vs. COM DLL

A COM object is in a thread as a running binary that is available to be used
by it's clients.

..NET Assemblies refer to DLLs that have MSIL not binary code. Do .NET obects
run in their own threads? Is it simply a matter of copying the object's MSIL
code so that the .NET object binary is not accessed in a thread the way COM
objects are?

--
Greg McPherran
www.McPherran.com
Jan 21 '06 #1
5 3612
A COM object is in a thread
What exactly do you mean by that?

Do .NET obects run in their own threads?
If you mean that there is one thread per object, then no.

Is it simply a matter of copying the object's MSIL
code so that the .NET object binary is not accessed in a thread the way COM
objects are?


Not sure what you mean by this either.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jan 24 '06 #2
Hello Mattias,

I seek an understanding of how objects are used at runtime in .NET as
compared to COM.

For example, with COM, an object is compiled and delivered as a native
binary. It must be registered on the target machine. Then when an app is run
and it uses the COM object, the COM object is loaded into a thread of the
application process at runtime (if I'm not mistaken).

For a .NET object (call it object_dotnet) that is in a DLL, is the object
itself loaded and JIT'ed when a client app uses it or is it built and JIT'ed
with the client app at compile time when the main app exe is created? Also,
from what I understand, .NET objects are in the same thread as the client
unike a COM object which uses a separate thread.

Any insight into the compile and run time differences between a COM and a
..NET appreciated.

Thank You
--
Greg McPherran
www.McPherran.com
"Mattias Sjögren" wrote:
A COM object is in a thread


What exactly do you mean by that?

Do .NET obects run in their own threads?


If you mean that there is one thread per object, then no.

Is it simply a matter of copying the object's MSIL
code so that the .NET object binary is not accessed in a thread the way COM
objects are?


Not sure what you mean by this either.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Jan 26 '06 #3
the COM object is loaded into a thread of the
application process at runtime (if I'm not mistaken).
I wouldn't say that the object is loaded "into" a thread.

For a .NET object (call it object_dotnet) that is in a DLL, is the object
itself loaded and JIT'ed when a client app uses it
Yes

Also, from what I understand, .NET objects are in the same thread as the client
unike a COM object which uses a separate thread.


No, COM objects don't automatically run on a separate thread. COM
objects and .NET objects work more or less the same in this regard.
The biggest difference is that in COM you may have to worry about
apartments, but the apartment concept doesn't exist in a pure .NET
world.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jan 26 '06 #4
Greg wrote:
For example, with COM, an object is compiled and delivered as a native
binary. It must be registered on the target machine. Then when an app
is run and it uses the COM object, the COM object is loaded into a
thread of the application process at runtime (if I'm not mistaken).
The point of registration is that it is a mechanism to associate the
unique name of the COM class (the CLSID) with the server that will be
used to create it. In other words it's a bit like a replacement for
LoadLibrary/GetProcAddress, except you don't have to give the name of
the server when instantiating a COM object, you just give the name of
the class.

Threading is handled through apartments. Most objects will specify the
type of apartment that they require because this also describes their
behaviour to being accessed by multiple threads. Only code in an
apartment can call COM objects so that means that all threads that
access (or host) COM object must be in apartments.

An STA object has no thread synchronization in its code and therefore it
can only be accessed by the same thread, if any other thread accesses
the object then the method call will be serialised as a Windows message
and put in the message queue attached to the STA thread. Periodically
the message queue is pumped for messages, and so the STA thread will get
the message and run the method. If an STA object creates another STA
object then the two will run in the same apartment (and their code will
only be called by the same STA thread).

An MTA object has thread synchronization in its code (or has code that
doesn't care about threads). The process will always have a thread pool
of threads that will run in the MTA. If an MTA thread creates an MTA
object and calls the object then methods will be run on that thread. If
an STA object creates an MTA object and calls it then a thread pool
thread (MTA thread) is used to make the call, so that means that there
is a transition from the STA thread to the MTA thread, and this is
called marshalling. Similarly if an MTA object creates and calls an STA
object then a new STA thread is created and the STA object will be
called on that thread and the inter-apartment (ie inter-thread) calls
will involve marshalling.

There are some COM objects that don't care what apartment they run in
(Both apartment type) and so these are created in the apartment of their
creators (STA or MTA). Note that STA objects are bound to the single
thread - they will always be called on the same thread - however an STA
thread can have more than one object. An MTA object can be called on any
of the threads in the MTA, so it is not bound to a particular thread.
For a .NET object (call it object_dotnet) that is in a DLL, is the
object itself loaded and JIT'ed when a client app uses it or is it
built and JIT'ed with the client app at compile time when the main
app exe is created?
Unless you use ngen (the native image generator), the code is just in
time compiled on a method-by method basis, that is just before a method
is called for the first time JIT compilation occurs. The code is then
cached and used for subsequent calls to this method in this instance of
the process. JIT compilation has a security aspect too - if your code
uses link demands and it is ngen'ed, ngen will be repeated if the
security policy is changed.
Also, from what I understand, .NET objects are in
the same thread as the client unike a COM object which uses a
separate thread.
They don't have to be <g> If you call an object's methods asynchronously
then a thread pool thread will be used.

Any insight into the compile and run time differences between a COM
and a .NET appreciated.


COM components are instantiated through a request to the COM runtime,
which is a little like an object broker - the COM runtime uses the CLSID
you provide to locate the server, it then loads the server and accesses
the class factory, and finally it requests an instance of the class with
the CLSID. This is dynamic linking and binding - as I said earlier, it
is a 'safe' equivalent of LoadLibraryEx and then calling GetProcAddress.

With .NET the linking and binding is static - the compiler *requires*
the metadata of the object when it compiles your code and a static
'link' is put in the assembly which effectively says 'create an instance
of this specific class in this specific assembly'.

Richard
--
Fusion Tutorial: http://www.grimes.demon.co.uk/workshops/fusionWS.htm
Security Tutorial:
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Jan 31 '06 #5
"Richard Grimes [MVP]" <ri******@mvps.org> wrote in message
news:Oq**************@TK2MSFTNGP10.phx.gbl...
For a .NET object (call it object_dotnet) that is in a DLL, is the
object itself loaded and JIT'ed when a client app uses it or is it
built and JIT'ed with the client app at compile time when the main
app exe is created?


Unless you use ngen (the native image generator), the code is just in time
compiled on a method-by method basis, that is just before a method is
called for the first time JIT compilation occurs. The code is then cached
and used for subsequent calls to this method in this instance of the
process. JIT compilation has a security aspect too - if your code uses
link demands and it is ngen'ed, ngen will be repeated if the security
policy is changed.


Why does all of this JIT / ngen stuff sound like "Free code for all" Plus
just begs for statements like.... "12ghz PC required"?

fwiw, we have an old VB3 app that runs fine, no matter what PC hardware you
throw at it... and plennnnty of VB6 generated binaries that do a great job
of hiding the source and still run on any PC we've ever had... from 286's to
3+ghz pentiums. No JIT, No ngen, No obfuscator, No problem.

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..
Mar 21 '06 #6

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

Similar topics

6
by: Tom Dacon | last post by:
If you're not putting assemblies in the GAC, but are referencing shared code with copylocal=true into the projects that use them, is there any value to signing the assemblies? In the environment...
6
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
3
by: Joel Leong | last post by:
I wish to know the industrial practices for signing assemblies with key files. I genereted a key file to sign my assemblies. Should I sign all my assemblies with a single key files or I shall...
1
by: Afaq | last post by:
Hi, After adding large number of empty resource files (which will be updated later), we are not able to compile the project. the following is the output of the build process. It fails while...
6
by: Sam-I-Am | last post by:
Hi There I have several websites that use shared assemblies in the GAC. When I try and update the GAC assemblies I get the following error: "The process cannot access the file because it is...
8
by: Jason | last post by:
In my ASP.NET 1.1 solutions, I created several web projects and compiled them each into an assembly. The assembly names reflected the functionality of the feature (Membership.dll, Dues.dll, etc)....
8
by: Charles Law | last post by:
I'm sorry to keep harping on about this one, but it is really quite important for me to be able to list _all_ required assemblies in my Help About box. Herfried kindly posted some code before that...
3
by: Claudio Pacciarini | last post by:
Hi everyone, I have a question about .NET code sharing and reuse, and also about application design best practices / guidelines. Currently, we have many different .NET projects in source...
2
by: Smithers | last post by:
I have a Windows Forms application that implements a plug-in architecture whereby required assemblies are identified and loaded dynamically. Here are the relevant classes: A = application =...
4
by: illegal.prime | last post by:
Hi all, I'm getting unexpected results when trying to preload assemblies into an AppDomain I'm creating. Upon creation of the AppDomain - I attach an AssemblyResolve to both my current AppDomain...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...

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.