I'm getting a run-time exception when I try to cast an object to an interface that I'm pretty sure it implements.
I have the following interfaces:
public interface class ISMILTimeContainer;
public interface class ISMILSequence : ISMILTimeContainer;
public interface class ISMILParallel : ISMILTimeContainer;
I have the following classes:
ref class TimeContainer : public ISMILTimeContainer;
ref class Sequence : public TimeContainer, ISMILSequence;
ref class Parallel : public TimeContainer, ISMILParallel;
Then, I try the following:
ISMILTimeContainer^ container = getSequence(); // returns a Sequence^
ISMILSequence^ sequence = static_cast<ISMILSequence^>(container);
This throws an exception at run-time:
Platform::InvalidCastException ^ at memory location 0x04AFD83C. HRESULT:0x80004002 No such interface supported
As far as I can tell, this should be working. Is there something wrong with what I'm trying to do, or do the symptoms indicate an implementation issue (something is different than what is claimed above)?
getSequence
? I tried to repro your code and do not get an exception. For me it works. All I changed was the line that callsgetSequence
to this:ISMILTimeContainer^ container = ref new Sequence();
PerhapsgetSequence
doesn't return aSequence
? – Cinchonidine