This is the weirdest programming problem I've seen for a long time.
I am using Microsoft Visual C# 2010 Express , C# and .NET 2.0 to develop an application. This application refers to a couple of dll / assemblies (all of these libraries are generated on my machine).
The following is part of the code (these are all basic things):
public class PowerManagement { [TestCase] public void PrepareTest(){ // Configure according to pre-conditions Preconditions precondition = new Preconditions(); precondition.SetupPreconditions(); ... } [TestCase] public void PerformTest(){ TestcaseData testcaseData = new TestcaseData(); // Set Trigger and perform check switch (testcaseData.triggerNumber){ case (1): if ((new Trigger1(testcaseData)).Validate() != 1) Report.TestStepFail("failed"); break; ... case (4): if ((new Trigger4(testcaseData)).Validate() != 1) Report.TestStepFail("failed"); break; default: Report.TestStepFail("Not yet implemented"); break; } } }
This application is then generated in a dll from Visual C# 2010 Express and used elsewhere, and everything is fine. The problem occurs when I add another case to the switch statement (see below)
... case (4): if ((new Trigger4(testcaseData)).Validate() != 1) Report.TestStepFail("failed"); break; case (5): if ((new Trigger5(testcaseData)).Validate() != 1) Report.TestStepFail("failed"); break; default: Report.TestStepFail("Not yet implemented"); break;
I can still build without a single problem and generate a dll, but when I use the generated dll, I get the following error:
A .NET exception (InvalidProgramException) occured in the module PowerManagement Error message: Common Language Runtime detected an invalid program. Throwing method: PowerManagement.PerformTest
(the problem occurs even if I copy case(4) and paste it as a new case, so it has nothing to do with Trigger5 -class)
What's going on here? I looked at the other InvalidProgramException and Common Language Runtime in Stackoverflow, but none of them were related.
I know this problem is strange , so please let me know and I will provide more information. I use a Windows 8 64-bit machine, if that matters. I have already checked for updates for VS and .NET updates. I havet also regenerated all dlls a couple of times and also created a solution from scratch a couple of times.