My first question is to wonder why you're trying to load an assembly from a
remote location even though it's already located and loaded locally where
your application is running?  But as to what's happening...

Because the assembly is being loaded from 2 different CODEBASEs, they are
treated as different assemblies in memory by the CLR.  This means that the
same type (as far as your concerned) is treated as 2 different types because
they're loaded from two different assemblies; which is why you cannot pass
instances of the "same" type across the assembly boundary.

You can verify that the CLR is treating them as different assemblies by
using Assembly.Load to get a reference to the one that your application
referenced and comparing it to the reference that's returned by
Assembly.LoadFrom for the remote assembly:

Assembly asmLinked = Assembly.Load("foolib");
Assembly asmLoaded = Assembly.LoadFrom(http://blah.com/foolib.dll);
bool sameAssemblies = ReferenceEquals(asmLinked, asmLoaded);

You'll see that sameAssemblies is false.

My original question notwhithstanding, one work around is to make the
assembly that you're building against strongly named and then use a CODEBASE
redirect in your application configuration file that directs the assembly
resolver to load it from the same codebase that you're going to be
downloading it from at runtime.

-Mike
http://staff.develop.com/woodring
http://www.develop.com/devresources

----- Original Message -----
From: "JP Hamilton" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, April 20, 2002 1:04 AM
Subject: [DOTNET] Loading remote assemblies


> I am trying to use Assembly.LoadFrom to load an assembly from a remote
> machine using a URL. I pass the appropriate evidence and the assembly is
> loaded fine. I am able to create objects and call methods at runtime....if
> the methods take no parameters or the parameters are .NET data types.
>
> What do I do if the method takes a type I have defined myself, like an
> enumeration? I keep getting an error that says 'Object cannot be converted
> to target type'. I have the remote assembly referenced locally, but do I
> really have two types in this situation. I thought Assembly.LoadFrom would
> load the type into the executing assembly. What am I missing?
>
> Any help would be greatly appeciated.
>
> JP
>
> You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.
>

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to