简体   繁体   English

C# 控制台应用程序中未处理的异常导致 AppCrash

[英]Unhandled Exception in C# Console Application causing AppCrash

I have a Windows Console application built in Visual Studio 2010 and it keeps crashing but the error is not caught by the visual studio debugging tool nor by try/catch statements in my code.我有一个在 Visual Studio 2010 中构建的 Windows 控制台应用程序,它不断崩溃,但 Visual Studio 调试工具和我的代码中的 try/catch 语句都没有捕获错误。

I have managed to locate the WER file on my system and would like to be able to understand the contents of the file so I can pinpoint exactally what is causing the unhandled exception.我已经设法在我的系统上找到 WER 文件,并希望能够理解文件的内容,以便我可以准确地查明导致未处理异常的原因。

I would be greatful if anyone can offer some idea on how I can use the following information to locate the process causing me this problem and also what the exception may be...如果有人可以提供一些关于如何使用以下信息来定位导致我出现此问题的进程以及可能是什么异常的想法,我将非常感激......

The information from the WER file is: WER文件中的信息是:

Version=1
EventType=APPCRASH
EventTime=129973086237604286
ReportType=2
Consent=1
ReportIdentifier=91331e8b-2dc8-11e2-977b-080027f7e5bb
IntegratorReportIdentifier=91331e8a-2dc8-11e2-977b-080027f7e5bb
WOW64=1
Response.type=4
Sig[0].Name=Application Name
Sig[0].Value=SAGE_TESTING.vshost.exe
Sig[1].Name=Application Version
Sig[1].Value=10.0.30319.1
Sig[2].Name=Application Timestamp
Sig[2].Value=4ba2084b
Sig[3].Name=Fault Module Name
Sig[3].Value=ntdll.dll
Sig[4].Name=Fault Module Version
Sig[4].Value=6.1.7600.16385
Sig[5].Name=Fault Module Timestamp
Sig[5].Value=4a5bdb3b
Sig[6].Name=Exception Code
Sig[6].Value=c015000f
Sig[7].Name=Exception Offset
Sig[7].Value=000845bb
DynamicSig[1].Name=OS Version
DynamicSig[1].Value=6.1.7600.2.0.0.272.7
DynamicSig[2].Name=Locale ID
DynamicSig[2].Value=2057
DynamicSig[22].Name=Additional Information 1
DynamicSig[22].Value=0a9e
DynamicSig[23].Name=Additional Information 2
DynamicSig[23].Value=0a9e372d3b4ad19135b953a78882e789
DynamicSig[24].Name=Additional Information 3
DynamicSig[24].Value=0a9e
DynamicSig[25].Name=Additional Information 4
DynamicSig[25].Value=0a9e372d3b4ad19135b953a78882e789

Here is the section of code I believe to be causing the exception to be thrown:这是我认为导致抛出异常的代码部分:

//Data from the project linked to the split data
if (oSplitData.Project != null)
{
    oProject = oSplitData.Project as SageDataObject190.Project;

    oBasicDetail.ProjectID = oProject.ProjectID;
    oBasicDetail.ProjectReference = oProject.Reference.ToString();
}
else
{
    oBasicDetail.ProjectID = -1;
    oBasicDetail.ProjectReference = "NO_PROJECT";
}

To add to all the above I seem to have found that there is a general exception that is being thrown but it doesn't help me out much - if anyone can put some light on this it would be great:除了上述所有内容之外,我似乎发现抛出了一个一般异常,但这对我没有多大帮助 - 如果有人能对此有所了解,那就太好了:

Unhandled exception at 0x78bc7361 in SAGE_TESTING.exe: 0xC0000005: Access violation reading location 0xfeeefeee.

If your program is multi-threaded and the exception is thrown in one of the spawned threads, the Exception may not be caught depending on how you do exception handling in your program.如果您的程序是多线程的并且异常是在产生的线程之一中引发的,则可能无法捕获异常,具体取决于您在程序中进行异常处理的方式。

You can add a catch-all exception handler like this:您可以像这样添加一个捕获所有异常处理程序:

class Program 
{
    static void Main(string[] args) 
    {
        AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
        // Your code here
    }

    static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e) 
    {
        Console.WriteLine(e.ExceptionObject.ToString());
        Environment.Exit(1);
    }
}

UPDATE更新

Based on the code you posted, here are some things to look at根据您发布的代码,这里有一些需要查看的内容

  • Put a try/catch block around the code you posted.在您发布的代码周围放置一个 try/catch 块。
  • Are you sure that oSplitData is not null?您确定oSplitData不为空吗?
  • In the following line, oProject will be null if oSplitData.Project is not of type SageDataObject190.Project.在以下行中,如果 oSplitData.Project 不是 SageDataObject190.Project 类型,oProject 将为null Test for null .测试null

    oProject = oSplitData.Project as SageDataObject190.Project; oProject = oSplitData.Project 作为 SageDataObject190.Project;

Are you invoking non-managed C++ or other code?您是在调用非托管 C++ 还是其他代码?

I'd try something like我会尝试类似的东西

static void Main()
{
  try
  {
    DoSomethingUseful() ;
  }
  catch ( Exception e )
  {
    // managed exceptions caught here
  }
  catch
  {
    // non-managed C++ or other code can throw non-exception objects
    // they are caught here.
  }
  return ;
}

See Will CLR handle both CLS-Complaint and non-CLS complaint exceptions?请参阅CLR 是否会同时处理 CLS 投诉和非 CLS 投诉异常?

Also C++ try, catch and throw statements at msdn:http://msdn.microsoft.com/en-us/library/6dekhbbc(v=vs.100).aspx还有 C++ try、catch 和 throw 语句在 msdn:http ://msdn.microsoft.com/en-us/library/6dekhbbc (v=vs.100).aspx

And MSIL opcode throw (0x7A) allows the throwing any object reference.而 MSIL 操作码throw (0x7A) 允许抛出任何对象引用。 C#, however, does not allow it.但是,C# 不允许这样做。

But it looks like they improved things with .Net 2.0 and started wrapping oddball stuff in an RuntimeWrappedException .但看起来他们用 .Net 2.0 改进了一些东西,并开始在RuntimeWrappedException包装奇怪的东西。

You are probably dealing with so-called corrupted state exceptions.您可能正在处理所谓的损坏状态异常。 These exceptions corrupt the process in a way so it is usually more safe to kill the process since it is very difficult to impossible to recover from such an error, even if it would be only for running a short catch-clause.这些异常以某种方式破坏了进程,因此杀死进程通常更安全,因为很难甚至不可能从此类错误中恢复,即使只是为了运行一个简短的 catch 子句。 Examples are StackOverflowExceptions, OutOfMemoryExceptions or AccessViolationExceptions.例如 StackOverflowExceptions、OutOfMemoryExceptions 或 AccessViolationExceptions。

There is an extensive and generally interesting explanation on corrupted state exceptions in this article .这篇文章中有一个关于损坏状态异常的广泛且普遍有趣的解释。

What is helpful on getting a hand on such exceptions is to use DebugDiag.帮助处理此类异常的方法是使用 DebugDiag。 With this tool from Microsoft ( download on this page ) you can define a crash rule which generates a crashdump for your failed process.使用 Microsoft 的这个工具( 在此页面下载),您可以定义崩溃规则,为失败的进程生成崩溃转储。 You can easily open these dump files in Visual Studio, where you may find the source of the exception that lead to the failure.您可以在 Visual Studio 中轻松打开这些转储文件,您可以在其中找到导致失败的异常来源。 This is not guaranteed but it often helped me in the past to nail down some nasty errors.这不能保证,但它在过去经常帮助我确定一些令人讨厌的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 空引用异常未处理的C#控制台应用程序 - Null Reference Exception was unhandled C# console application C# Windows 表单应用程序未处理异常 - C# Windows Form Application Unhandled Exception C#MultiThreading导致类型为'System.OutOfMemoryException'的未处理异常 - C# MultiThreading is causing unhandled exception of type 'System.OutOfMemoryException' C#控制台应用程序-在找到可用和可用的Ram空间时出现未处理的异常。在Windows窗体应用程序中获取确切答案 - C# console application - Unhandled exception while finding the Available and free Ram space.Getting exact answer in windows forms application c#console app error(由于未处理的异常导致进程终止) - c# console app error (The process was terminated due to an unhandled exception) C#中未处理的异常 - Unhandled Exception in c# 部署后,应用程序退出/关闭时APPCRASH错误C# - APPCRASH error C# on Application Exit/Close after Deployment C#应用程序中未处理的异常会导致应用程序崩溃吗? - Unhandled exception in C# application does it crash the app? C# 如何调查:应用程序引发了未处理的异常 - C# How to investigate: An unhandled exception was thrown by the application C#控制台应用程序无效的操作异常 - C# console application Invalid Operation Exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM