你好.标题怎么说,如何显示.NET Core或Standard Class Library方法中的消息框?我需要执行此操作,因为如果必须使用try/catch语句,我想显示一个带有异常消息错误的消息框.我尝试添加Winforms 引用类库,但找不到System.Windows.Forms.dll.
Hello. How the title says, how I can show a message box in a method of a .NET Core or Standard Class Library? I need to do this because If I have to use try/catch statment, I want to show a message box with the exception message error. I tried adding winforms reference to class library but I cannot found System.Windows.Forms.dll. Any suggestion?
推荐答案
您正在开发哪种.NET Core应用程序?是Web应用程序还是控制台应用程序?
What kind of .NET Core application are you developing? Is it a Web Application or a Console Application?
无论哪种情况,您都可以在catch块中设置如下所示的断点:
Either case you can set a breakpoint in the catch block written like this:
try { //Your code } catch(Exception e) { //You can put a breakpoint on the line above }当断点停止运行代码时,您可以检查e中的异常消息.
and when the breakpoint stops the code from running you can inspect the exception message from e.
您还可以在catch块中添加 Console.WriteLine(e.Message)并在控制台中查看错误.
You can also add Console.WriteLine(e.Message) in the catch block and see the error in the Console.
如果您正在开发Web应用程序,并且想稍后再回来查看错误,那么最好在项目中使用记录器.有关记录器的更多信息,请访问docs.microsoft/zh-cn/aspnet/core/fundamentals/logging
If you are developing a web application and you want to come back and see the error later, then it's better to use a logger with your project. For more information on loggers look at docs.microsoft/en-us/aspnet/core/fundamentals/logging
希望有帮助.
更多推荐
在.NET Core/标准类库中显示消息框
发布评论