G
Guest
I am having a problem where I create an instance of a class from an assembly
and I try to cast it to an interface that it inherits from and it says that
the cast is invalid.
Here is the code:
Interface.IParser objPlugin;
Interface.PluginServices parserService = new Interface.PluginServices();
objPlugin = (Interface.IParser)parserService.CreateInstance(_parser);
return objPlugin.ParserName;
the CreateInstance above is a function that calls Assembly.LoadFrom and then
subsequently createInstance. Everything in that function seems to operate
normally returning an instance of my class that is contained in the assembly
testParser.TestParser which implements Interface.IParser which is an
interface class that I wrote.
The problem is that the line
"objPlugin = (Interface.IParser)parserService.CreateInstance(_parser);"
causes an invalid cast exception.
and I try to cast it to an interface that it inherits from and it says that
the cast is invalid.
Here is the code:
Interface.IParser objPlugin;
Interface.PluginServices parserService = new Interface.PluginServices();
objPlugin = (Interface.IParser)parserService.CreateInstance(_parser);
return objPlugin.ParserName;
the CreateInstance above is a function that calls Assembly.LoadFrom and then
subsequently createInstance. Everything in that function seems to operate
normally returning an instance of my class that is contained in the assembly
testParser.TestParser which implements Interface.IParser which is an
interface class that I wrote.
The problem is that the line
"objPlugin = (Interface.IParser)parserService.CreateInstance(_parser);"
causes an invalid cast exception.