> So my application code calls Assembly.LoadFrom() on the assembly, > executes the method and the returned class is used in the calling code. > However, I believe the calling code loads the assembly from the GAC in > the Load context (via a static reference) in order to define a variable > of the class returned from the method, and Assembly.LoadFrom() will > load > the assembly into the LoadFrom context. The class returned from the > method is not compatible with the class variable defined in the calling > code as they are in different contexts and I get the Invalid Cast > exception.
I'm not sure I fully grasp what you're trying to do (sorry), but would separate AppDomains help? You could specify the private path (where Assembly.Load looks for DLLs) in the AppDomainSetup when you create the new AppDomain, and there'll be no conflict between that assembly and any other assembly in your current context. You can't pass objects between AppDomains, but you can serialise objects or pass MarshalByRefObject object references, so (with a bit of glue code in your new AppDomain) this may do what you need. Hope this helps, Geoff =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com