Casting problem

  • Thread starter Thread starter Alexander Brown
  • Start date Start date
A

Alexander Brown

I run the following code:

Control control = pluginInstance.Control;
Console.WriteLine("type is "+control.GetType());
NewControl castControl = (NewControl)control;

The Console has "type is MyNamespace.NewControl" written to it. However the
third line of code throws a "Specified case is not valid exception".
Can anyone tell me why this would be? I get the impression that there is
something fundamental to the language that i have overlooked!

Thanks,
Alex
 
I run the following code:
Control control = pluginInstance.Control;
Console.WriteLine("type is "+control.GetType());
NewControl castControl = (NewControl)control;

The Console has "type is MyNamespace.NewControl" written to it. However the
third line of code throws a "Specified case is not valid exception".
Can anyone tell me why this would be? I get the impression that there is
something fundamental to the language that i have overlooked!


Have you used Assembly.LoadFrom() to load your plugin library? If so,
I suggest you read this

http://www.gotdotnet.com/team/clr/LoadFromIsolation.aspx



Mattias
 
Alexander Brown said:
I run the following code:

Control control = pluginInstance.Control;
Console.WriteLine("type is "+control.GetType());
NewControl castControl = (NewControl)control;

The Console has "type is MyNamespace.NewControl" written to it. However the
third line of code throws a "Specified case is not valid exception".
Can anyone tell me why this would be? I get the impression that there is
something fundamental to the language that i have overlooked!

See http://www.pobox.com/~skeet/csharp/plugin.html

That might not be the problem, but it may well be...
 
If I understand the doc correctly you *cannot* load another version of an
assembly that is already loaded even if they have different minor versions
because the runtime will consider the assembly as already loaded, and
LoadFrom will return the already loaded assembly instead of the new one. Is
that right?

And if I have a dll in my appliction's folder and one in my GAC LoadFrom
will always load the one from the GAC because it will look there first, even
if the one from the gac is an older one?
 
Back
Top