B
b0yce
Hi all,
I have been looking around the newsgroups and various resources but have
found no clear distinct answer to when and why you should use
AppDomain.CreateInstance or Activator.CreateInstance when loading Assemblies
dynamically.
My scenario is;
HostA is a service, when it starts it creates an instance of
HostedObjectA and puts this on a TCP port ready for remote communication as
a singleton. This is all through a reference.
ClientA connects to HostedObjectA via the TCP channel remotely, then via
the proxy, ClientA calls a method on HostedObjectA passing FileName &
TypeName of an assembly to load and instantiate within HostedObjectA.
HostedObjectA then loads up the assembly using either
Activator.CreateInstance(...).UnWrap() or
AppDomain.CreateInstance(...).UnWrap() methods.
The Activator method works fine and creates the object, but the
AppDomain method does not work and throws "File or assembly name [filename],
or one of its dependencies, was not found.".
I then created a dummy test, with all files not having any dependencies,
apart from the normal system references, but still get the same outcome.
I am fine with that Activator works, but I would like to know why it
does and why AppDomain.CreateInstance does not work, it's makes for better
undesrtanding.
So anyone care to enlighten?
Cheers in advance
b0yce
I have been looking around the newsgroups and various resources but have
found no clear distinct answer to when and why you should use
AppDomain.CreateInstance or Activator.CreateInstance when loading Assemblies
dynamically.
My scenario is;
HostA is a service, when it starts it creates an instance of
HostedObjectA and puts this on a TCP port ready for remote communication as
a singleton. This is all through a reference.
ClientA connects to HostedObjectA via the TCP channel remotely, then via
the proxy, ClientA calls a method on HostedObjectA passing FileName &
TypeName of an assembly to load and instantiate within HostedObjectA.
HostedObjectA then loads up the assembly using either
Activator.CreateInstance(...).UnWrap() or
AppDomain.CreateInstance(...).UnWrap() methods.
The Activator method works fine and creates the object, but the
AppDomain method does not work and throws "File or assembly name [filename],
or one of its dependencies, was not found.".
I then created a dummy test, with all files not having any dependencies,
apart from the normal system references, but still get the same outcome.
I am fine with that Activator works, but I would like to know why it
does and why AppDomain.CreateInstance does not work, it's makes for better
undesrtanding.

So anyone care to enlighten?
Cheers in advance
b0yce