InvalidProgramException /通用语言运行时检测到一个无效的程序 [英] InvalidProgramException / Common Language Runtime detected an invalid program

查看:844
本文介绍了InvalidProgramException /通用语言运行时检测到一个无效的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我见过在很长一段时间的最奇怪的编程问题。

This is the strangest programming issue I have seen in a long time.

我使用微软的Visual C#2010例preSS C# .NET 2.0 来开发应用程序。该应用程序引用了几个 DLL 的/组件(都在我的机器上生成这些DLL)。

I am using Microsoft Visual C# 2010 Express, C# and .NET 2.0 to develop an application. This application references a couple of dll/assemblies (those dlls are all generated on my machine).

下面的code部分(这是所有基本的东西):

Below is part of the code (it is all basic stuff):

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;
        }
    }
}

该应用程序,然后生成到 DLL 的Visual C#2010例preSS 和其他地方使用,一切都很好。这个问题表面当我添加另一起案件的switch语句以上(见下文)

This application is then generated into a dll from Visual C# 2010 Express and used elsewhere and all is fine. The problem surfaces when I add another case to the switch-statement above (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;

我仍然可以建立没有一个单一的问题,产生的dll,但是当我使用生成的DLL我收到以下错误:

I can still build without a single issue and generate the 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

(问题是即使我复制情况下(4),并将其粘贴为新的情况,所以它无关 Trigger5 级)

(the issue happens even if I copy case(4) and paste it as a new case, so it has nothing to do with Trigger5-class)

这是怎么回事?我已经通过看其他 InvalidProgramException 公共语言运行库在#1,但似乎没有关系。

What is happening here? I have looked through the other InvalidProgramException and Common Language Runtime in Stackoverflow but none seemed related.

我知道这个问题很奇怪所以请让我知道,我会提供更多的信息。我使用的是64位的Windows 8机器,如果该事项。我已经检查了在VS和.NET更新的任何更新。我havet也重新生成所有的DLL几个时间ANS也创造了从无到有的解决方案几次。

I know this issue is strange 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.

推荐答案

我终于成功地解决了这个问题。 我在C#中前preSS取消选中 code优化并解决的问题。不过最奇特的地方,但由于我们使用的是旧的工具和框架,我们真的不能责怪任何人。

I finally managed to solve this issue. I unchecked code optimization in C# Express and that solved the issues. Still the weirdest thing, but since we are using old tools and framework we can not really blame anyone.

这篇关于InvalidProgramException /通用语言运行时检测到一个无效的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆