exception - All unit tests throwing BadImageFormatException with Moq? -


i'm in process of increasing code coverage on our software products , have ran issue; of unit tests (when compiled using 'any cpu') failing due throwing 'badimageformatexception'.

this exception can circumvented building solution using 'x86' instead of 'any cpu', requirements such need able run them using cpu/x64 bit.

all unit tests involving moq follow pretty same format:

[testmethod] public void getproduct_validid_productreturned() {     //setting object     product prod = new product();     prod.id = 7;     prod.name = "test";      //create mocks     var mockproductrepo = new mock<irepository<product>>();     var testdb = new mock<iunitofwork>();      //setup repo needs return, in case it's product     mockproductrepo.setup(m => m.getbyid(7)).returns(prod);       //setup database needs return, in case it's our repo we've setup     testdb.setupget(m => m.productrepo).returns(mockproductrepo.object);      //run test     product returnedprod = producthelper.getproduct(testdb.object, 7);     assert.isnotnull(returnedprod); } 

i can confirm test successful when built using x86. have ideas on how can moq play nice when built using 'any cpu'?

as aside can confirm projects in solution build using same value ('any cpu'). i'm using moq v4.0.

edit: here full exception: test method [productname , method called] threw exception: system.badimageformatexception: not load file or assembly '[product name], version=1.0.0.0, culture=neutral, publickeytoken=null' or 1 of dependencies. attempt made load program incorrect format.

ok after digging found out issue was. if select 'build' , 'configuration manager' toolbar , see platform set 'any cpu' (as case), hadn't done check target platform in project.

to check target platform need following:

  • right-click project , select 'properties'
  • select 'build' tab on left
  • ensure target platform of test project matches of project testing

in case test targeting 'any cpu' live project targeting 'x64'. causing issue.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -