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
Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

InvalidProgramException when running tests with mstest

0 votes
Every once in a while I get an InvalidProgramException when I run tests via the command line tool mstest.exe. As this exception is thrown in case of invalid IL, it could be related to the changes made on-the-fly by TypeMock.

I have researched this extensively without being able to exactly pinpoint what is going wrong. The error only appears in about 10% of the runs and only if the TypeMock environment variables are enabled (i.e. by setting the following environment variables:)

set Cor_Enable_Profiling=0x1
set COR_PROFILER={B146457E-9AED-4624-B1E5-968D274416EC}

The test suite in questions doesn't use TypeMock but the test project does reference TypeMock. I'm unable to reproduce the error if I set Cor_Enable_Profiling=0x0.

I can't say for sure if this is caused by TypeMock or not. However, if I disable TypeMock I am unable to reproduce the error. Please let me know if there is any way for you to verify if TypeMock is or isn't the source of the error.

I'm using (Enterprise) and Visual Studio 2005 Team Suite.
asked Jul 17, 2006 by brian.rasmussen (7,160 points)

17 Answers

0 votes

Please upgrade to and see if this still happens. We fixed a problem that fits the scenario you mentioned.

If it still happens please start TypeMock with logging - (It is best to create a specific directory). Use TMockRunner -logPath or the TypeMock MSBuild Task.
Run the tests that fail and send the logs with the test results (*.trx) file.
answered Jul 17, 2006 by scott (31,960 points)
0 votes

Upgrading to 3.5.1 certainly helped. However, very rarely I still get a COM-interop exception when running the tests. This may be something completely different tough. I have seen vstesthost fail from time to time and I suspect that this may actually be related to that. The test cases do not use COM at all so this exception must be thrown by "the environment".

answered Jul 25, 2006 by brian.rasmussen (7,160 points)
0 votes
Are you using code coverage when this happens?
Could you please send the complete error.
answered Jul 25, 2006 by scott (31,960 points)
0 votes
Hi again,

I may have been a bit to quick to accept the patch, cause after additional testing I still get the "invalid program" error from time to time. However, I have now identified a single test where this error can be reproduced.

It appears that I can only reproduce the error when running the tests via an ordered test list using mstest. I'm not using code coverage at the moment (I don't even have a testrunconfig file).

If I disable mocking (via the environment variable Cor_Enable_Profiling=0x0), I'm unable to reproduce the error.

The error message from the .trx file is listed below. Please let me know if you need any additional information.

  <message type="System.String">Test method SimCorp.IMS.Threading.Test.HostManagerTest.ExecuteCommand threw exception: System.InvalidProgramException: Common Language Runtime detected an invalid program..</message> 
  <stackTrace type="System.String">at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(Boolean condition, String message) at SimCorp.IMS.Threading.Test.HostManagerTest.ExecuteCommand() in C:workspacesThreadingTestMainDevelopmentSimCorpIMSThreadingTestHostManagerTest.cs:line 60</stackTrace> 
- <traceInfo type="Microsoft.VisualStudio.TestTools.Common.TestExecutionTraceInformation">
  <trace type="System.Text.StringBuilder">Calling class initialization method SimCorp.IMS.Threading.Test.HostManagerTest.MyClassInitialize. Creating instance of class SimCorp.IMS.Threading.Test.HostManagerTest. Calling initialization method SimCorp.IMS.Threading.Test.HostManagerTest.MyTestInitialize. Calling Test method SimCorp.IMS.Threading.Test.HostManagerTest.Microsoft.VisualStudio.TestTools.TestTypes.Unit.TestMethod.</trace> 
answered Jul 31, 2006 by brian.rasmussen (7,160 points)
0 votes

I too am working with this problem. The testsuite I am working on is frozen and has been for months yet I am migrating the build to msbuild / 2.0 and have been forced to upgrade to 3.5.1.

* The exception is never thrown using NUnit 2.2.2
* The exception is thrown but swallowed in 2.2.6 (appears when debugging, swallowed since it is thrown on other thread in my case)
* The exception is thrown and causes test failure in 2.2.8 (2.2.8 seems to have improved error reporting and does report exceptions thrown on other thread in a better way)

* Previous version of Typemock and 2.2.6 does not throw

As Brian says - it is most difficult to pinpoint. It always says "CLR detected an invalid program in UNKNOWN module".

I will continue working and see if I can find anything more.
answered Jul 31, 2006 by mawi (2,040 points)
0 votes
Thanks Brian and Mawi
I have taken this offline and I will post a reply here as soon as posible.
Of course if one of you have a test that can re-create the problem
please feel free to post it or send it to me ... 8)
answered Jul 31, 2006 by ohad (35,440 points)
0 votes
Hi Brian and Mawi
You can download version 3.5.2.
Please tell me it fixed your problem.
answered Aug 25, 2006 by ohad (35,440 points)
0 votes
Hi Ohad,

Thanks for the update. I tested it today and unfortunately I am still able to reproduce the InvalidProgramException (and the COMException for that matter). I can supply you the log files as before but unless you have changed your logging I doubt they will show anything new. Would it be possible to get a special dll with additional logging in the hope that we can narrow in on the source of the error?

answered Aug 29, 2006 by brian.rasmussen (7,160 points)
0 votes

I too have upgraded and 3.5.2 does not address the problem.

Previously I did not get the COMException (BadBinarySignature), yet I do so now at least as frequently as the InvalidProgramException.

I will contact you (Ohad) to get you the log files and my comments.

answered Sep 8, 2006 by mawi (2,040 points)
0 votes
Hi Marcus
I got your mail. Thanks for your detailed report. 8)
We are looking into it now and I will let you know as soon as we will have something.
answered Sep 9, 2006 by ohad (35,440 points)