控制台应用程序 - 无法捕获未处理的异常
我编写了一个非常简单的 C# 控制台应用程序,它将打开 Crystal Report、刷新它并将其作为 PDF 保存到指定位置。
在 VS2005 中运行时一切正常; pdf 文件按预期生成。 当我将 .exe 复制到我的根 C: 驱动器并从命令行运行它时,我会看到一个对话框,指出“CrystalGenerator 已停止工作” - 但仍会生成 pdf 文件! 查找此对话框的可能原因表明发生了未处理的异常,但 Main 方法的全部内容包含在 try/catch 中,因此这不是我的问题。
查看事件日志,我看到许多条目指出“无法找到插入索引 (%1) 的替换字符串”,但无法找到对此含义的合理解释。
好处是,如果我将文件复制到运行 Server 2003 的机器(打算运行的地方),则命令运行时不会出现错误 - 但我想知道为什么该应用程序在 Vista 上行为不当以及如何解决它。
提前致谢。
I have written a very simple C# Console Application which will open a Crystal Report, refresh it and save it as a PDF to a specified location.
When running within VS2005 everything runs fine; the pdf file is generated as expected. When I copy the .exe to my root C: drive and run it from the command line I get a dialog box stating that "CrystalGenerator has stopped working" - but the pdf file is still generated!
Looking up possible causes of this dialog indicate that an Unhandled Exception has occured but the entire contents of the Main method is contained within a try/catch so that can't be my problem.
Looking in the event log I see a number of entries stating "The substitution string for insert index (%1) could not be found" but cannot find a sensible explanation of what this means.
The upside is that if I copy the file to a box running Server 2003 (where it is intended to run) the command runs without error - but I want to know why the app misbehaves on Vista and how to resolve it.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您从提升的命令提示符(WinKey,然后按 cmd,然后按 Ctrl+Shift+Return)运行应用程序,它是否有效?
您正在调用的进程之一可能需要提升。
Does it work if you run the app from an elevated command prompt (WinKey followed by pressing cmd followed by Ctrl+Shift+Return)?
It might be that one of processes you are calling requires elevation.
如果出于某种原因导致堆栈溢出,则无法捕获它,因为无法可靠地展开调用堆栈。
在这种情况下,您的应用程序将像您所说的那样运行。
If for whatever reason, you are causing a stackoverflow, it cannot be caught, because there is no way to reliably unwind the callstack.
In that situation, your application will behave like you said.
经过大量的链接追踪后,看起来这种行为是“设计使然”!
StackOverflows 的 Jeff Atwood 也遇到过这个问题(请参阅此处)并在 Microsoft Connect 上提出了该问题(请参阅此处)。
看起来我将寻找一种替代方法 - 尽管代码确实可以在 Server 2003 上运行。
感谢 divo 的建议,这些建议非常有帮助。
Well after a lot of link-chasing it looks like this behaviour is 'By Design'!
StackOverflows own Jeff Atwood experienced the problem (see here) and raised the issue on Microsoft Connect (see here).
Looks like I will be looking for an alternate approach - although the code does work on Server 2003.
Thanks to divo for your suggestions which were very helpful.