> Is it possible to do a "weak reference" (not a weak reference in GC-terms!!)
> to the needed assemblies, so that the loader does not complain if those
> assemblies where not found?
> From your code you could easily check if the needed assembly was loaded, and
> if not, take a different codepath preventing use of the not loaded assembly.

You could use Reflection to load the assembly into an Assembly object
and to instantiate your type, e.g. (compiled with Gmail):

AssemblyName name = new AssemblyName("myassembly");

// set name's properties as needed

Assembly assembly = null;
try {
  assembly = Assembly.Load(name);
}
catch (Exception) { // specialize this if needed
}

IMyObject myObject = null;
if (assembly != null) {
  Type myObjectType = assembly.GetType("MyObject1");
  myObject =(IMyObject)Activator.CreateInstance(myObjectType);
}
else {
  myObject = new MyObject2();
}

(I haven't tried it out, so I might've missed something important. And
you should probably add some error checking as well.)

Fabian

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to