Thanks for the help, guys. I will try out your suggestions. Charles.
-----Original Message----- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Fabian Schmied Sent: 16 May 2007 12:54 To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: Re: [ADVANCED-DOTNET] Using Assembly.LoadFrom instead of Assembly.Load() > I have an assembly that contains a method that returns a class that is > also defined in that assembly. > The assembly is in the GAC. > > However, for my application, I want to use Assembly.LoadFrom() to load > the assembly from a file path also. The assembly is already referenced by your application. Then, why exactly do you want to load it by file path as well? Do you actually need two different _versions_ of the assembly in memory? If yes, switching to Assembly.Load (or any other loading mechanism) won't help at all, since the types will still not be compatible. If no, Assembly.LoadFile might help, as Prakash suggested, since it doesn't load the assembly into the LoadFrom context. However, LoadFile has other problems (e.g. that it doesn't resolve dependencies). > 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. Your analysis is right, but I don't really understand why you are running into the problem in the first place :-) > I would like to be able to load the assembly using it's file path, but I > want it to be in the Load context so the calling code will work. > I realise, this may sound like a strange request, the issue is that the > assembly is a 3rd party assembly/add in and we have no control over > whether it will be in the GAC or not. : ) LoadFile will probably help you. But understand that the problem is not that the assembly is in the GAC (or not), it is that the assembly is loaded _twice_ when you only require it _once_ :-) Fabian =================================== This list is hosted by DevelopMentor(r) http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com ________________________________________________________________________ This e-mail has been scanned for all viruses by MessageLabs. ________________________________________________________________________ ________________________________________________________________________ This e-mail has been scanned for all viruses by MessageLabs. Singularity operates globally through its offices in New York, London, Singapore, Ireland and India. Singularity Limited is incorporated in the United Kingdom with Registration Number NI 31519 and its Registered Office at 100 Patrick Street, Derry, BT48 7EL, United Kingdom. ________________________________________________________________________ =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com