Hi, I want to create an object from a class I load from an assembly.
Then I want to cast that object to a class (an interface) 'known' to the
program in order to pass it to other methods that work with that interface.
The casting is invalid but I can't see why, as the class I load from the
assembly really is of the type I cast it to.
Command a = (Command) t.GetConstructo r(new
Type[0]).Invoke(System .Reflection.Bin dingFlags.Publi c,null,null,nul l);
What can be the cause of the cast being invalid? I tried to cast it to
almost everything that might be possible. I didn't find any examples on
the Internet that do really cast the object.
I know I can invoke a method on the returned object by using Invoke(..
but that's not really the purpose.
Maybe somewhat clearer:
ConstructorInfo ci = t.GetConstructo r(new Type[0]);
object o = ci.Invoke(Syste m.Reflection.Bi ndingFlags.Publ ic,null,null,nu ll);
Command a = (Command) o;
-> Invalid cast exception
t.FullName
-> program.shell.t extualshell.com mands.command
Type tt = o.getType();
tt.FullName
-> program.shell.t extualshell.com mands.command
I'm totally in the dark here..
Please do not hesitate to ask additional information if necessary.
Thanks in advance.