chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male

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:UserskentrDocumentsProjectsExcessionAlphaTrader.UnitTestbinDebugAlphaTrader.dll'.
    Type B originates from 'AlphaTrader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'C:UserskentrAppDataLocalTempTypemockExcessionTypemock.SmartRunner.Agent.exeassemblydl32564a603f408e132_ad89d201AlphaTrader.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, 2017 by KentRollins (15,290 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, 2017 by eli (5,060 points)
selected Feb 25, 2017 by KentRollins
...