InvalidCastException in test runner

0 votes

I am getting some type errors that appear to have something to do with assembly identity.  Here is the test code:

ICandidateScorer ifScorer =
    InterfaceLoader.InstantiateInterface<ICandidateScorer>(sAlphaTraderAsy, sAlphaPredictorScorer);
Assert.IsInstanceOfType(ifScorer, typeof(AlphaPredictorScorer));
ifScorer.Initialize(sScorerFile);
AlphaPredictorScorer scorerAP = (AlphaPredictorScorer)ifScorer;
The Assert.IsInstanceOfType() is failing which the following message:
Assert.IsInstanceOfType failed.
    Expected type:<Kent.AlphaTrader.AlphaPredictorScorer>.
    Actual type:<Kent.AlphaTrader.AlphaPredictorScorer>.

The cast from ifScorer to scorerAP is failing with the following exception:

System.InvalidCastException :
    [A]Kent.AlphaTrader.AlphaPredictorScorer cannot be cast to
    [B]Kent.AlphaTrader.AlphaPredictorScorer.
    Type A originates from 'AlphaTrader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' at location 'C:\Users\kentr\Documents\Projects\Excession\AlphaTrader.UnitTest\bin\Debug\AlphaTrader.dll'.
    Type B originates from 'AlphaTrader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'C:\Users\kentr\AppData\Local\Temp\Typemock\Excession\Typemock.SmartRunner.Agent.exe\assembly\dl3\2564a603\f408e132_ad89d201\AlphaTrader.dll'.

It appears the the Typemock test runner is modifying the original assembly such that .NET no longer recognizes the types that the code was originally compiled against.

Is there a way to deal with this?

 

asked Feb 19 by KentRollins (260 points)

1 Answer

+1 vote
 
Best answer

Hi,

This can happen when the assembly is loaded from different dlls. You probrably have your own Assembly loader within InterfaceLoader.

Please try to disable smartRunner from running in shadowcopy. (see here)

answered Feb 19 by eli (5,770 points)
selected Feb 26 by KentRollins
...