如何覆盖 Debug.Assert(在 C# 中)并使其在没有 Visual Studio 的情况下工作
当我第一次尝试 C# 编程时,我很高兴看到错误报告终于有了一些进展。断言、异常和内部异常在 Visual Studio 中很容易调试。不幸的是这种兴奋并没有持续多久,现在我注意到越来越多的限制,例如 BeginInvoke 中的错误调用堆栈报告,已发布的 ASP.NET 应用程序中的错误行号报告,在没有 Visual Studio 的计算机上绝对没有错误信息(桌面应用程序的调试版本)等等。所以最终 C# 错误报告与 C++ 错误报告一样糟糕。
所以,我的问题是,有没有办法强制 Debug.Assert 在所有版本中工作,使其报告正确的行号和调用堆栈信息,特别是当不从 Visual Studio 执行时,尤其是甚至没有安装 Visual Studio 时?
When I first tried C# programming I was very glad to see that finally there's some progress in error reporting. Assertions, exceptions and inner exceptions where easy to debug in visual studio. Unfortunately this excitement wasn't long lived, now I'm noticing more and more limitations, such as buggy callstack-reporting in BeginInvoke, buggy line-number-reporting in released asp.net applications, absolutely no error information on computers without visual studio (debug builds of desktop applications), etc. So in the end C# error reporting is just as ass as C++ error reporting.
So, my question is, is there a way to force Debug.Assert to work in all builds, make it report correct line-numbers and callstack information, especially when not executing from visual studio, especially when not even having visual studio installed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
调用堆栈中的行号不依赖于或不需要 Visual Studio。它们需要在构建过程中创建的 PDB 文件。如果您的 EXE 和 DLL 在同一文件夹中具有相应的 PDB 文件,则所有堆栈跟踪(来自异常/断言)都将包含行号。
Line numbers in callstacks do not depend on or require Visual Studio. They requires the PDB files created during the build process. If your EXEs and DLLs have their corresponding PDB files in the same folder, all stack traces (from exceptions/asserts) will contain line numbers.