InvalidProgramException/公共语言运行时检测到无效程序 [英] InvalidProgramException / Common Language Runtime detected an invalid program

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

问题描述

这是我在很长一段时间内看到的最奇怪的编程问题.

我正在使用 Microsoft Visual C# 2010 ExpressC#.NET 2.0 来开发应用程序.这个应用程序引用了几个 dll/assemblies(这些 dll 都是在我的机器上生成的).

下面是代码的一部分(都是基本的东西):

公共类PowerManagement{[测试用例]公共无效准备测试(){//根据前置条件配置先决条件 precondition = new Preconditions();precondition.SetupPreconditions();...}[测试用例]公共无效 PerformTest(){TestcaseData testcaseData = new TestcaseData();//设置触发器并执行检查开关(testcaseData.triggerNumber){情况1):if ((new Trigger1(testcaseData)).Validate() != 1)Report.TestStepFail("失败");休息;...案例(4):if ((new Trigger4(testcaseData)).Validate() != 1)Report.TestStepFail("失败");休息;默认:Report.TestStepFail("尚未实现");休息;}}}

此应用程序然后从 Visual C# 2010 Express 生成为 dll 并在其他地方使用,一切正常.当我在上面的 switch 语句中添加另一个 case 时,问题就出现了(见下文)

<代码> ...案例(4):if ((new Trigger4(testcaseData)).Validate() != 1)Report.TestStepFail("失败");休息;案例(5):if ((new Trigger5(testcaseData)).Validate() != 1)Report.TestStepFail("失败");休息;默认:Report.TestStepFail("尚未实现");休息;

我仍然可以在没有任何问题的情况下构建并生成 dll,但是当我使用生成的 dll 时,我收到以下错误:

PowerManagement 模块中出现 .NET 异常 (InvalidProgramException)错误消息:公共语言运行时检测到无效程序.投掷方法:PowerManagement.PerformTest

(即使我复制case(4)并将其粘贴为新案例也会出现问题,因此它与Trigger5-class无关)

这里发生了什么?我已经查看了 Stackoverflow 中的其他 InvalidProgramExceptionCommon Language Runtime,但似乎没有任何相关性.

我知道这个问题很奇怪所以请告诉我,我会提供更多信息.如果重要的话,我使用的是 64 位 Windows 8 机器.我已经检查了 VS 和 .NET 更新的任何更新.我也有几次重新生成了所有的 dll,也有几次从头开始创建了解决方案.

解决方案

我终于设法解决了这个问题.我在 C# Express 中取消选中 code optimization 并解决了问题.仍然是最奇怪的事情,但由于我们使用的是旧工具和框架,我们不能真正责怪任何人.

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

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).

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

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;

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

(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)

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

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.

解决方案

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天全站免登陆