简体   繁体   English

C#-Visual Studio在运行时崩溃,在外部运行已编译程序的效果很好

[英]C# - Visual Studio crashes at runtime, running the compiled program externally works fine

I'm trying to pick up C# (I'm somewhat comfortable with C++, but Qt goes way over my head) but I'm running into a show-stopping issue with MSV. 我正在尝试使用C#(我对C ++有点满意,但是Qt超出了我的脑袋),但是我遇到了MSV令人震惊的问题。

Namely, sometimes when I build & run my code the resulting program will crash, where if I build it and run it outside of the IDE it works as intended. 即,有时在我构建和运行代码时,最终的程序将崩溃,而在我构建并在IDE外部运行它的情况下,它将按预期工作。

I've come across this issue a few different times on a few different programs, and I don't always get the same error code, but the result is always the same - the console window appears but nothing is written to it; 我在几个不同的程序上遇到了几次不同的问题,但我并不一定总是得到相同的错误代码,但是结果总是相同的-控制台窗口出现了,但没有写入任何内容; it hangs for a second, and then 'vshost32.exe has stopped working' pops up. 它挂起一秒钟,然后弹出“ vshost32.exe停止工作”。 Following the error message's debug option does nothing, as it says it isn't configured. 错误消息的debug选项后面没有执行任何操作,因为它未配置。

Here's an example of a complete program that's giving me the issue: 这是一个完整程序的示例,它给了我这个问题:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            int number1, number2, number3;

            Console.WriteLine("Please enter a number:");
            number1 = int.Parse(Console.ReadLine());

            Console.WriteLine("Please enter another number:");
            number2 = int.Parse(Console.ReadLine());

            Console.WriteLine("Calculating...");
            number3 = number1 * number2;

            switch (number3)
            {
                case 0:
                    Console.WriteLine("The result is equal to zero.");
                    break;
                case 1:
                    Console.WriteLine("The result is equal to one.");
                    break;
                default:
                    Console.WriteLine("The result is not equal to zero or one.");
                    break;
            }

            Console.ReadLine();
        }
    }
}

Here's where it gets stranger. 这就是它变得陌生的地方。

Commenting out the case statements removes the problem entirely. 注释掉case陈述可以完全消除问题。 It compiles and runs properly from the editor, and runs without an issue. 它可以从编辑器编译并正常运行,并且运行没有问题。 However, I can't see any reason why the two case statements would be causing an issue. 但是,我看不到任何两个case语句都会引起问题的原因。 For the record, this program exits with code "-1073741819 (0xc0000005) Access violation". 作为记录,该程序以代码“ -1073741819(0xc0000005)访问冲突”退出。

Just to humor the IDE and see if it really was a problem in my code, I ran the first example program from this page: http://csharp.net-tutorials.com/basics/switch-statement/ And the same thing happened . :只是为了幽默的IDE,看看它是否真的是在我的代码有问题,我从这个页面运行的第一个例子程序http://csharp.net-tutorials.com/basics/switch-statement/同样的事情发生了 Hang, crash, 0xc0000005 Access violation. 挂起,崩溃,0xc0000005访问冲突。 And, just like before, when I manually run the .EXE file outside of the IDE it works just fine. 而且,就像以前一样,当我在IDE外部手动运行.EXE文件时,它也可以正常工作。

I reinstalled .NET Framework a few times to see if that was the issue and it wasn't - I even tried rolling back from 4.5.3 to 4.5, that just broke it even more. 我重新安装了.NET Framework几次,以查看是否是问题所在,但不是-我什至尝试将其从4.5.3回滚到4.5,这甚至使它更加崩溃了。 Right now I'm totally stumped, because I can't really do much of anything as long as I have to leave the IDE to run my code. 现在,我很沮丧,因为只要离开IDE运行我的代码,我实际上就无法做任何事情。 I'm running Windows 10 (b10041) and am using Visual Studio 2013. 我正在运行Windows 10(b10041),并且正在使用Visual Studio 2013。

In the project there is a bin folder with an exe in the debug and release folder. 在项目中,在debug和release文件夹中有一个带exe的bin文件夹。 Make sure when you compile the date of the exe is getting updated. 确保在编译exe的日期时得到更新。 You are probably are not using the latest exe file. 您可能没有使用最新的exe文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#项目在Visual C#Express程序编辑器上工作正常,但发布后停止工作 - C# Project Works Fine on Visual C# Express Program Editor but Stops Working When Published 是否可以从 Visual Studio 编译 C# 程序以在 Mac 上运行? - Is it possible to compile a C# program from Visual Studio for running on Mac? 在 Visual Studio Code 中使用命令行提示运行 C# 程序 - Running a C# program with command line prompts in Visual Studio Code 运行在Linux中使用Mono编译的C#程序 - Running C# program compiled with Mono in Linux 如何从Windows C#(Visual Studio)运行cygwin编译的程序? - How do you run a cygwin-compiled program from windows c# (visual studio)? 如何将未编译的内容与通过Visual Studio发布的C#程序一起包含在内 - How to include non-compiled content alongside a C# program published via Visual Studio 简单的 C# 应用程序无法正常工作,在 Visual Studio 中运行时工作正常 - Simple C# application not working correctly, works fine when run from within Visual Studio 在运行时格式化Visual Studio C#报表 - Formatting Visual Studio C# Reports at runtime WinRT c# 编译为 exe 但不在 Visual Studio 外部运行 - WinRT c# compiled to exe but does not run outside visual studio Visual Studio的C#彩票循环程序 - c# Lottery looping program with Visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM