visual studio 2012 - VS2012 Native Unit Test Fails with ZLib: "Failed to setup the execution context" -


adding link dependency zlibwapi.lib causes of unit tests fail message "failed setup execution context run test". unfortunately, message not provide enough detail troubleshoot problem. extremely useful know why test execution context not setup, e.g., cannot load some.dll because of some_reason.

other postings have noted dependent libraries must in same directory, not fix problem. dumpbin.exe tool shows adding link dependency zlibwapi.lib adds zlibwapi.dll imports section. also, zlibwapi.dll's import section contains kernel32.dll , msvcr110d.dll present in unit test library's import section. non-standard dependent libraries in unit test runtime folder , still fails.

the problem reproducible downloading zlib, building in visual studio 2012 sp3, , adding native unit test. specifically:

  1. download zlib128.zip http://www.zlib.net.

  2. follow these tips (http://bugbeebox.com/2012/12/29/building-static-zlib-v1-2-7-with-msvc-2012/) build on visual studio 2012.

  3. add native unit test project named zlibunittest ...\zlib-1.2.8\contrib\vstudio\vc11. in build\configuration manager, add x64 bit platform new project, verify it's build checkbox checked, , choose x64 active solution platform. it's useful add project dependency zlibunittest zlibvc ensure correct build order.

  4. modify unittest1.cpp's testmethod1 appear as:

    test_method(testmethod1) {     assert::areequal(0, 0); } 

    set test --> test settings --> default processor achitecture x64 , verify runs correctly in test explorer.

  5. modify zlibunittest configuration properties follows:

    a) add ..\..\..\..\; c/c++ --> general --> additional include directories zlib.h can found. b) add $(outdir); linker --> general --> additional library directories zlibwapi.* can found. c) add zlibwapi.lib; linker --> input --> additional dependencies. d) add copy ..\x64\zlibdlldebug\zlibwapi.* $(outdir) build events --> pre-build event zlib runtime libraries in same directory unit test library binaries.

  6. modify unittest1.cpp's testmethod1 appear as:

    test_method(testmethod1) {     assert::areequal(0, 0);     gzopen(null, null); } 

    the null args gzopen not relevant error because never gets far.

  7. run unit test in test explorer , generic error "failed setup execution context run test".

  8. now, comment out gzopen call in testmethod1 , remove zlibwapi.lib additional linker dependencies , watch error disappear.

does know how make zlib work visual studio 2012 native unit tests?

at least, know how more detail on particular error, i.e., unit test runtime log somewhere?

it turns out zlib had bug caused require windows 8 runtime. apparently running unit tests on windows 7 development machine caused mysterious , unnecessarily cryptic "failed setup execution context" error.

once applied fix https://stackoverflow.com/a/17113126/2319854 zlib , rebuilt all, unit tests started working again.


Comments