c# - 特定机器上 C# 控制台应用程序的奇怪问题

标签 c#

我有最简单的 C# 控制台应用程序,它只执行 WriteLine 和 ReadLine。由于某种原因,它不会在其构建的机器上以独立模式运行。我在另一个盒子上尝试了构建的可执行文件,它工作正常。

尝试在这台机器上运行它会使它卡在那里。它在 VS 中工作正常,只是在命令行中不行。

尝试将 VS 附加到挂起的进程时,会出现类似于“ConsoleApplication1 已触发断点”的内容,但看不到问题所在(它表明断点是 ntdll.dll 中的 _LdrpDoDebuggerBreak@0())。

关于如何诊断正在发生的事情有什么想法吗?

编辑(回答下面的评论):发布和调试都会发生相同的行为。平台设置为自动。测试的两台机器都是 64 位的。它正在处理的是 Windows 7,我正在构建(以及它挂起的地方)的是 Windows 10。

EDIT2:我注意到的另一件事是尝试运行该应用程序不会调出控制台窗口(因此它在此之前挂起)。另外,附加到挂起进程后分离也会挂起 VS。

EDIT3:这是完整的压缩项目:(已删除)。它也包含用于好奇的调试 .exe 文件。它只是一个带有以下代码的普通控制台应用程序项目:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
        Console.WriteLine("ASD");
        Console.ReadLine();
    }
  }
}

最佳答案

您确定您的代码中除了 WriteLine() 和 ReadLine() 之外什么都没有吗?我还没有测试过,但这听起来正是我期望调用 Debugger.Break() 的行为。 .

MSDN 页面有注释:

Starting with .NET Framework 4, the runtime no longer exercises tight control of launching the debugger for the Break method, but instead reports an error to the Windows Error Reporting (WER) subsystem. WER provides many settings to customize the problem reporting experience, so a lot of factors will influence the way WER responds to an error such as operating system version, process, session, user, machine and domain. If you're having unexpected results when calling the Break method, check the WER settings on your machine. For more information on how to customize WER, see WER Settings. If you want to ensure the debugger is launched regardless of the WER settings, be sure to call the Launch method instead.

在它工作的机器上,它要么忽略这一行,因为你没有安装开发工具,要么你的设置让它跳过它。在您正在开发的机器上,设置会有所不同。费用可能基于 Windows 7 和 10 默认值,但我不知道。

关于c# - 特定机器上 C# 控制台应用程序的奇怪问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33908905/

相关文章:

c# - 为什么异步回调套接字方法通常是静态的?

c# - 设计状态链

c# - 无法从静态方法访问 asp 控件,但是当我删除静态方法时,ajax 调用将不起作用

c# - ASP.NET Core 2 的 SignInManager 依赖注入(inject)失败

c# - 将部分 View 加载到模态弹出窗口中

c# - 从集合中删除在 Nhibernate 中不起作用

c# - 在构建解决方案而非项目时,C# 7 中的值元组因 MSBuild.exe 而失败

c# - html敏捷包: Find second table within a div

c# - JSON反序列化不调用属性方法

c# - 在 C# 中将任意类型实例写入 MemoryStream