title: InvalidProgramException / Common Language Runtime detected an invalid program
body: <p>This is the strangest programming issue I have seen in a long time.</p>
  
  <p>I am using <code>Microsoft Visual C# 2010 Express</code>, <code>C#</code> and <code>.NET 2.0</code> to develop an application. This application references a couple of <code>dll</code>/assemblies (those dlls are all generated on my machine).</p>
  
  <p>Below is part of the code (it is all basic stuff):</p>
  
  <pre><code>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;
          }
      }
  }
  </code></pre>
  
  <p>This application is then generated into a <code>dll</code> from <code>Visual C# 2010 Express</code> and used elsewhere and all is fine. The problem surfaces when I add another case to the switch-statement above (see below)</p>
  
  <pre><code>        ...
          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;
  </code></pre>
  
  <p>I can still build without a single issue and generate the dll but when I use the generated dll I get the following error:</p>
  
  <pre><code>A .NET exception (InvalidProgramException) occured in the module PowerManagement
  Error message: Common Language Runtime detected an invalid program.
  Throwing method: PowerManagement.PerformTest
  </code></pre>
  
  <p>(the issue happens even if I copy <code>case(4)</code> and paste it as a new case, so it has nothing to do with <code>Trigger5</code>-class)</p>
  
  <p>What is happening here? I have looked through the other <code>InvalidProgramException</code> and <code>Common Language Runtime</code> in Stackoverflow but none seemed related.</p>
  
  <p><strong>I know this issue is strange</strong> so please let me know and I will provide more information. I am using a 64-bit Windows 8 machine, if that matters. I have already checked for any updates on VS and .NET updates. I havet also regenerated all the dlls a couple of time ans also created the solution from scratch a couple of times.</p>