为什么我的 .NET 控制台应用程序在未运行 Main 的情况下退出?
我刚刚打开了一个控制台应用程序的源代码,该应用程序是几年前部署的,作为我们服务器上的 Windows 计划任务每天运行两次(它更新数据库中的某些内容)。部署时运行得很好,但现在我们需要进行一些代码更改。我尝试在调试中运行它,程序甚至不会进入子主程序。它到达了 static void Main(string[] args) 行
并结束运行。控制台窗口消失。我没有从客户那里听说生产版本没有运行,但是当我检查他们的服务器时,我没有看到我应该看到的事件日志条目(应用程序应该在每次运行时写入事件日志) )
I just opened up the source code for a console application that was deployed a couple years ago to run twice a day as a windows scheduled task on our server (it updates something in the database). When it was deployed was running just fine, but now we need to make some code changes. I try to run it in Debug and the program won't even enter sub main. It hits the line
static void Main(string[] args) and just ends running. The console window disappears. I haven't heard from the clients that the production version isn't running, but when I check their servers I don't see the Event Log entries that I should (the app is supposed to write to the Event Log each time it runs)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是 DLL 问题。
如果
Main()
使用 JITter 无法找到的程序集中的类型,则程序将在命中Main()
之前终止。如果包含
Main()
的类型具有无法加载的类型的字段,也会发生这种情况。如果该类型的静态构造函数调用Environment.FailFast(),也可能会发生这种情况。
This is probably a DLL issue.
If
Main()
uses types from an assembly that the JITter can't find, the program will die before hittingMain()
.This would also happen if the type containing
Main()
has fields of a type that couldn't be loaded.It could also happen if that type's static constructor calls
Environment.FailFast()
.如果您运行应用程序的计算机上没有正确版本的 .NET Framework,我也遇到过这种情况。
也许您在重新编译时更改了目标框架版本。
I have also seen this occur if you don't have the correct version of .NET framework on the machine you're running the application on.
Perhaps you changed the target framework version when you recompiled it.