1

.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!

Andrew Florko
  • 7,672
  • 10
  • 60
  • 107

1 Answers1

1

Have you tried RuntimeCompatibilityAttribute.WrapNonExceptionThrows?

Alternatively, a catch block without a type should catch non CLS-compliant exceptions, i.e:

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.

Johannes Kommer
  • 6,401
  • 1
  • 39
  • 45
  • The OP says he doesn't get an exception. In fact he says this approach doesn't work at all. Reread the question. –  Nov 18 '11 at 10:19
  • 1
    @Inuyasha The OP says that the `catch` block does not work at all, he does not say whether he was doing `catch (exception ex) { }` or just `catch { }`, he also didn't mention whether wrapping is enabled or not. Either of which could solve his problem if he is getting non CLS-compliant exceptions. – Johannes Kommer Nov 18 '11 at 10:28