Simon X-Session <x-session@gmx.at> wrote:[color=blue][color=green]
> > This usually happens if you've got the base class/interface present in
> > two different assemblies - the dynamically loaded one and the
> > "driving" one. Put it in just one place, and you should be fine.[/color]
>
> i don't know if i understand you right
> i need to have the interface in both assemblys, otherwise it wouldn't
> compile[/color]
No you don't. You need to add a reference to the assembly which
contains the interface in order to compile against it.
You may well decide to put the interface in a separate (and thus very
small) assembly on its own, and add a reference to that assembly for
both of the other assemblies.
<snip>
[color=blue]
> loading of assembly and instatiation of class works flawlessly, but as
> soon as i want to cast the object reference to the interface, it fails
> drop the line where i cast to the interface and uncomment the test to
> cast to "TestClass"
> even this fails in runtime
> notive the output of ToString() of instance
> it says CastTest.TestClass !!
> so this class should be save to be casted[/color]
No it shouldn't - because if you output GetType()==typeof(ITest) you'll
find they're not the same types. Basically you end up with two separate
types in memory, both for the same type name. The cast is using the
version loaded in its assembly, but the actual type is the one in the
assembly containing the test class.
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too