简体   繁体   English

在特定计算机上使用C#console app的奇怪问题

[英]Weird issue with C# console app on a specific machine

I have the simplest C# console app that only does a WriteLine and a ReadLine. 我有最简单的C#控制台应用程序,它只能执行WriteLine和ReadLine。 For some reason, it doesn't run in standalone mode on the machine it was built. 出于某种原因,它不会在它构建的机器上以独立模式运行。 I tried the built executable on another box and it works fine. 我尝试在另一个盒子上构建可执行文件,它工作正常。

Trying to run it on this machine makes it just hang there. 试图在这台机器上运行它只是挂在那里。 It works fine inside VS, just not from the command line. 它在VS内部工作正常,而不是从命令行。

Trying to attach VS to the hanging process says something along the lines of "ConsoleApplication1 has triggered a breakpoint" but can't see what the problem is (it indicates the breakpoint is _LdrpDoDebuggerBreak@0() in ntdll.dll). 尝试将VS附加到挂起进程时说“ConsoleApplication1已触发断点”,但无法看到问题所在(它表示断点是ntdll.dll中的_LdrpDoDebuggerBreak @ 0())。

Any ideas on how to diagnose what's going on? 关于如何诊断正在发生的事情的任何想法?

EDIT (answering comments below): Same behavior happens for both Release and Debug. 编辑(回答下面的评论):发布和调试都会发生相同的行为。 Platform is set to Auto. 平台设置为自动。 Both machines tested on are 64-bit. 测试的两台机器都是64位。 The one it's working on is Windows 7, the one I'm building on (and where it hangs) is Windows 10. 它正在开发的是Windows 7,我正在构建的那个(以及它挂起的地方)是Windows 10。

EDIT2: Something else I noticed is that trying to run the app doesn't bring up a console window (so it hangs before that). EDIT2:我注意到的其他事情是尝试运行应用程序没有调出控制台窗口(因此它在此之前挂起)。 Also, detaching after attaching to the hanging process also hangs VS. 此外,附加到挂起过程后分离也挂起VS.

EDIT3: Here's the full zipped project: (removed). EDIT3:这是完整的压缩项目:(已删除)。 It contains the debug .exe file as well for the curious. 它包含调试.exe文件以及好奇。 It's just a vanilla console application project with the following code: 它只是一个带有以下代码的vanilla控制台应用程序项目:

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

Are you sure that there's nothing in your code except a WriteLine() and a ReadLine()? 除了WriteLine()和ReadLine()之外,您确定代码中没有任何内容吗? I haven't tested it, but this sounds like exactly the behavior I would expect from calling Debugger.Break() . 我没有测试它,但这听起来就像我期望调用Debugger.Break()的行为。

The MSDN page has a note: 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. 从.NET Framework 4开始,运行时不再严格控制启动Break方法的调试器,而是向Windows错误报告(WER)子系统报告错误。 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. WER提供了许多设置来自定义问题报告体验,因此很多因素将影响WER响应错误的方式,例如操作系统版本,进程,会话,用户,计算机和域。 If you're having unexpected results when calling the Break method, check the WER settings on your machine. 如果在调用Break方法时遇到意外结果,请检查机器上的WER设置。 For more information on how to customize WER, see WER Settings. 有关如何自定义WER的详细信息,请参阅WER设置。 If you want to ensure the debugger is launched regardless of the WER settings, be sure to call the Launch method instead. 如果要确保无论WER设置如何启动调试器,请务必调用Launch方法。

On the machine where it is working, it's either ignoring this line because you don't have development tools installed, or your settings are such that it just skips it. 在它正在工作的机器上,它要么忽略这一行,因为你没有安装开发工具,要么你的设置只是跳过它。 On the machine you're developing on, the settings would be different. 在您正在开发的机器上,设置会有所不同。 Possibly fees are based on the Windows 7 and 10 defaults, but I don't know. 可能的费用是基于Windows 7和10的默认值,但我不知道。

Finally figured it out. 终于想通了。 It's my lovely antivirus. 这是我可爱的杀毒软件。 Hoping this helps someone in the future, Avast doesn't bring up the usual prompt indicating it's scanning the app or quarantining it or anything. 希望这可以帮助将来的某个人,Avast没有提出通常的提示,表明它正在扫描应用程序或隔离它或任何东西。 Disabling the shields (Avast Shields Control -> Disable for 10 mins) makes the app work properly. 禁用防护罩(Avast Shields Control - >禁用10分钟)可使应用程序正常工作。 Argh! 哎呀!

Thank you all for the support! 谢谢大家的支持!

Interestingly the other machine where it works is still running Avast, but I think it's one major version behind. 有趣的是,它工作的另一台机器仍在运行Avast,但我认为它是一个主要版本。 This is for version 10.4.2233. 这适用于版本10.4.2233。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM