简体   繁体   中英

How do I isolate unmanaged code crash in .Net Process

.Net Console Application depends on COM objects that tend to crash from time to time in very unpredictable way. Application simply closes with no reason at all: no logs, no exceptions ( catch block doesn't work at all), no event logs, nothing about the error occured.

How can I isolate native crashes? Will AppDomain approach save me?

Thank you in advance!

Have you tried RuntimeCompatibilityAttribute.WrapNonExceptionThrows ?

Alternatively, a catch block without a type should catch non CLS-compliant exceptions , ie:

try
{
    // Code here.
    // Maybe a COM call here.
}
catch(Exception ex)
{
    // Managed exceptions.
}
catch
{
    // non CLS-compliant exceptions.
}

Using a seperate AppDomain will most likely not work depending on why exactly your application is getting killed off in the first place as unhandled exceptions will still kill the entire process and currently your exception is unhandled as you haven't caught it.

Alternatively you could use the COM objects within a separate process and use inter process communication between the two. This would isolate the problematic code into it's own process which you can then restart / use as needed without your main process being killed off.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM