4

I have a Console application which look as below,

static void Main(string[] args) 
{
    try
    {
        System.AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;
        // My Code
    }
    catch(Exception ex)
    {
    }
}

static void UnhandledExceptionTrapper(object sender, UnhandledExceptionEventArgs e) 
{
    // The code.
}

In the above code neither the catch is firing nor UnhandledExceptionTrapper. It suddenly says application stopped working. Event viewer has no important info about crash. Event viewer says some file exist but when check nothing there. I am using .NET 4.6.1.

The code just pulls data from oracle (using dapper) and using TransactionScope.

Edit: We have found the culprit line. It was doing a Update in Oracle wrapped inside TransactionScope. The problem is that unable to catch these exception and its coming sometimes and failing most of the time. These are sample code that uses Dapper to update Oracle.

using (var scope = new TransactionScope())
{
   UpdateOracleUsingDapperMethod();
   scope.Complete();
}

Related: https://github.com/dotnet/runtime/issues/30422

Imran Qadir Baksh - Baloch
  • 32,612
  • 68
  • 179
  • 322
  • It may have something to do with unmanaged libraries... Are you using one? – Kzryzstof Aug 05 '18 at 14:50
  • No I am using Dapper and Transaction Scope – Imran Qadir Baksh - Baloch Aug 05 '18 at 14:56
  • A bunch of stuff needs to happen *before* your Main() method can run and subscribe the event. The just-in-time compiler needs to run first, it can easily fail with a FileNotFoundException. It is worse in the Release build, now it needs to try to inline method calls so more code needs to be jitted. Any static variables with a field initializer are notable, may well run and keel over before Main() starts executing. Make it better by moving the code in the `// My Code` block into another static method. It needs [MethodImpl(MethodImplOptions.NoInlining]) to slow down the jitter. – Hans Passant Aug 05 '18 at 14:58
  • @HansPassant I can debug the first few lines of code but after than it crashes – Imran Qadir Baksh - Baloch Aug 05 '18 at 15:01
  • 1
    Some exceptions are too nasty to handle and trigger a failfast. Like the one this website is was named after, there [are others](https://stackoverflow.com/a/13567016/17034). Look at the Output window for the process exit code. Some can be reported anyway, look at [this Q+A](https://stackoverflow.com/q/39956163/17034). – Hans Passant Aug 05 '18 at 15:11
  • @user960567 Could you start the application with some tool like WinDbg? You may get more information about the crash. This tool has been helpful to me so many times when weird crashes happen on the field :) – Kzryzstof Aug 05 '18 at 15:14
  • @HansPassant Kzrystop we found the reason for crash. It was simple Update statement in Oracle that make the application crash but sometimes it works and sometimes it crash. – Imran Qadir Baksh - Baloch Aug 05 '18 at 15:40
  • @user960567 Out of curiosity, have you been able to get some information about the crash? Like the exception that seems to bypass the UnhandledException handler? – Kzryzstof Aug 05 '18 at 15:51
  • No info that's the problem. It seems there is exception on db side that is not caught.Unlucky so far. – Imran Qadir Baksh - Baloch Aug 05 '18 at 16:43
  • Great thread - could it be that the exception is being "swallowed" somewhere (being caught deeper)? – EdSF Aug 05 '18 at 17:54
  • @EdSF try is the first line and catch is last line and still crashes – Imran Qadir Baksh - Baloch Aug 05 '18 at 18:28
  • @HansPassant andd Kzrystop moving OleDbConnection to OracleConnection fixed the crash issue. Thanks for help. – Imran Qadir Baksh - Baloch Aug 07 '18 at 11:27
  • @user960567 Was it something like an access violation in unmanaged code? – Kzryzstof Aug 07 '18 at 12:01
  • @Kzrystof I don't have more info because I am using OleDbConnection abstraction don't know under the hood what it does. May be Hans knows :) – Imran Qadir Baksh - Baloch Aug 08 '18 at 07:06

1 Answers1

1

We found the issue is related to OleDbConnection. So, we moved to OracleConnection and no crash. This means using Oracle in Dapper with TransactionScope and OleDbConnection have some serious issues.