[英]System.ComponentModel.Win32Exception: The operation completed successfully
[英]'System.ComponentModel.Win32Exception: The operation completed successfully' while debugging unit test
我的课堂上有解扰器,我正在析构函数上启动cmd进程。 我在调试单元测试时遇到了此异常。 我的课 :
class Class1
{
~Class1()
{
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.Start();
}
}
我的单元测试:
[TestMethod]
public void TestMethod1()
{
Class1 class1 = new Class1();
}
当我在调试模式下运行项目时,也不例外。 如何解决这个问题? 有人遇到这样的问题吗?
在测试周围放置一个try catch
块。
[TestMethod]
public void TestMethod1()
{
try
{
Class1 class1 = new Class1();
class1 = null;
// force Garbage Collection for finalizer to run
GC.Collect();
}
catch(Win32Exception w)
{
Console.WriteLine(w.Message);
Console.WriteLine(w.ErrorCode.ToString());
Console.WriteLine(w.NativeErrorCode.ToString());
Console.WriteLine(w.StackTrace);
Console.WriteLine(w.Source);
Exception e=w.GetBaseException();
Console.WriteLine(e.Message);
}
}
这将为您提供确切的错误消息。
这可能与未设置路径一样简单。 如果是这样的话。 返回的错误将是file not found
。 在那种情况下,可以通过将"cmd.exe"
更改为@"C:\\windows\\system32\\cmd.exe"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.