I think you're trying to be too tricky. The runtime will note when an assembly is already loaded without appreciable overhead in an Activator.CreateInstance() call. Just create the instance of the type, and don't worry about trying to avoid re-loading GOURMET or the others.
One question, though: Is this system already running, or currently in the design phase? An attempt to create an instance of a type that's not yet had its assembly loaded will generate an exception from within the CLR whether you want it or not. (You can hook the AppDomain.AssemblyResolve event to handle the situation when the assembly cannot be found, but IIRC the exception is what triggers this event.) That means you'll have to know the instance's type ahead of time (meaning it has to be present in the XML message), which then means you will have to load the assembly yourself, which could in turn drag in other dependent assemblies, many or most of which you may consider to be unnecessary. You're also begging for a versioning problem here, if node #1 sends a Foo(v2) instance to node #2 still running with Foo(v1) instances in it, since now you're going to want to load Foo(v2).dll and Foo(v1).dll simultaneously. It's doable, but you are playing with fire in many respects here. In a lot of ways you're looking to recreate a mobile object scenario. There's an article in MSDN Mag this month (haven't read it yet, don't know how good it is) on just this subject, might want to take a look. Bear in mind, though, that Java went down this path for a while and it was not as easy as it seemed. ClassCastExceptions were the rule of the day. :-/ (Unfortunately, one vendor who really got the story right there went out of business and their product got slurped into a larger CORBA ORB story. Sad, really.) Ted Neward Author, Presenter, Consultant Java, .NET, XML services http://blogs.tedneward.com > -----Original Message----- > From: Discussion of advanced .NET topics. [mailto:ADVANCED- > [EMAIL PROTECTED] On Behalf Of Jekke Bladt > Sent: Wednesday, January 04, 2006 3:13 PM > To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM > Subject: Re: [ADVANCED-DOTNET] Is this System.Assembly an executable or a > library? > > Yes. Here's the premise. > > We have a messaging system so that all of our trading machines can talk > to each other using MSMQ. The messaging system (GOURMET) is generic and > context free. All the messages are passed as interfaces > (IRemoteMessage.) > > Each application that wants to speak remotely creates its own class that > implements IRemoteMessage in its own library. With the exception of the > central trading framework application (TKS,) nearly all of our > applications are distributed as libraries that are loaded dynamically at > runtime. These include applications with specific trading logic and > applications like GOURMET, which provide services for the trading logic > applications. > > For any given workstation, we have no idea what applications a trader > might be running other than TKS. When the GOURMET system is receiving > messages, it's getting self-describing XML nodes that contain all of > their own metadata. Using this metadata, it attempts to deserialize into > a clone of the object that was sent on the other end of the line. But, > not all of the messages it receives will be of recognizable types. A > given machine might not have the appropriate assembly or the appropriate > assembly version to recreate the class that generated the message. Since > GOURMET can be handling up to 500 messages per second, it has to be very > efficient. Two artitectural directives are to avoid using exceptions to > determine the absence of a library and to avoid loading unnecesary > assemblies into memory. This includes all executables since we know that > any executable is either (a) already running or (b) outside of the > domain of meaningful messages for the currently running application. > > --Jekke > > -----Original Message----- > From: Discussion of advanced .NET topics. > [mailto:[EMAIL PROTECTED] On Behalf Of David > Lanouette > Sent: Wednesday, January 04, 2006 5:37 PM > To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM > Subject: Re: [ADVANCED-DOTNET] Is this System.Assembly an executable or > a library? > > > Jekke, > > I don't think I understand. Why do you think you need to explicitly > load the assembly. > > Are you loading classes using reflection? > > > > On 1/4/06, Jekke Bladt <[EMAIL PROTECTED]> wrote: > > If the assembly in question is a library, I want to be able to load it > > into memory before creating a class out of it. This is for a system > that > > sends messages of various types over MSMQ in serialized XML with no > way > > of guaranteeing that the listener will already have the assembly > loaded. > > > > The only assemblies we could guarantee would be running are the > > executable and the messaging library (aka GOURMET.) Since message > types > > are defined in the executable, GOURMET, and third-party libraries, > we're > > trying to avoid trying to load either GOURMET or the executable at > > runtime (when they are guaranteed to already be loaded.) > > > > --Jekke > > > > -----Original Message----- > > From: Discussion of advanced .NET topics. > > [mailto:[EMAIL PROTECTED] On Behalf Of Eric Means > > Sent: Wednesday, January 04, 2006 4:42 PM > > To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM > > Subject: Re: [ADVANCED-DOTNET] Is this System.Assembly an executable > or > > a library? > > > > > > > System.IO.Path.GetExtension(Assembly.GetModules()[0].FullyQualifiedName) > > would work similarly. > > > > From a practical perspective, I'm not sure there's much difference > > between > > an EXE assembly and a DLL assembly, except that the EXE contains a > shim > > to > > kick off the .Net core and start the EXE's Main() function. Out of > > curiousity, why do you need to know? > > > > On 1/4/06, David Lanouette <[EMAIL PROTECTED]> wrote: > > > > > > I doubt that this is the best way, but... > > > > > > if > (Assembly.GetExecutingAssembly().Location.EndsWith(".dll")) > > > Console.WriteLine("Dll"); > > > else > > > Console.WriteLine("exe"); > > > > > > > > > > > > > > > > > > On 1/4/06, Jekke Bladt <[EMAIL PROTECTED]> wrote: > > > > All-- > > > > > > > > Is there a straightforward way to determine from an Assembly > object > > > > whether it is an executable or a library? > > > > > > > > TIA > > > > > > > > --Jekke > > > > > > > > =================================== > > > > This list is hosted by DevelopMentor(r) http://www.develop.com > > > > > > > > View archives and manage your subscription(s) at > > > http://discuss.develop.com > > > > > > > > > > > > > -- > > > ______________________________ > > > - David Lanouette > > > - [EMAIL PROTECTED] > > > > > > =================================== > > > This list is hosted by DevelopMentor(r) http://www.develop.com > > > > > > View archives and manage your subscription(s) at > > > http://discuss.develop.com > > > > > > > > > > > -- > > Eric Means > > [EMAIL PROTECTED] > > http://www.randomtree.org/eric/ > > > > =================================== > > This list is hosted by DevelopMentor(r) http://www.develop.com > > > > View archives and manage your subscription(s) at > > http://discuss.develop.com > > > > =================================== > > This list is hosted by DevelopMentor(r) http://www.develop.com > > > > View archives and manage your subscription(s) at > http://discuss.develop.com > > > > > -- > ______________________________ > - David Lanouette > - [EMAIL PROTECTED] > > =================================== > This list is hosted by DevelopMentor(r) http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com > > =================================== > This list is hosted by DevelopMentor. http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com