Here's the situation: I am using ILMerge to merge an assembly & all it's references into 1 .dll file using this method (custom.dll
). I have an application which dynamically loads this assembly at runtime (program.exe
). Both application & assembly use a common library (common.dll
). Abstract class ClassX
is defined in common.dll
whilst implementation ClassY
is defined in custom.dll
. When program.exe
tries to load ClassY from custom.dll
it throws the exception:
Unable to cast object of type 'ClassY' to type 'ClassX'.
The code is like this, but foo
is dynamically loaded rather than just a straight new ClassY();
object foo = new ClassY();
ClassX bar = (ClassX)foo;
Does anyone have any idea why it would do this? ClassY
definitely implements ClassX
, all assembly/library versions are exactly the same.