0

I'm working on a C# WPF application. I'm using a DLL (not developed by me). I'm using it like this (simplified):

try
{
    Bitmap bmp = new Bitmap(filePath);

    // Use the DLL
    var worker = theDLL.loadImage(bmp);

    status state = worker.start();

    if (state = theDLL.sta.OK)
    {
        return "OK"
    }
    else
    {
        state = worker.tryOtherMethod();
    }
}
catch (Exception e)
{
    // Do something with e
}

Sometimes (not always) I have a Unhandled exception. This exception is not catch and my application crash :

An invalid parameter was passed to a function that considers invalid parameters fatal.

I saw that this exception comes from C++ code but i'm unable to catch it (even with AppDomain.CurrentDomain.UnhandledException or Dispatcher.UnhandledException).

How can I prevent the crash ?

Edit:

I've try to catch the exception with catch alone and catch (Win32Exception e) but both didn't solve my problem.

I still have this error :

enter image description here

A.Pissicat
  • 3,023
  • 4
  • 38
  • 93
  • Do you get the problem sometimes with the same file, or with different files? Is it possible you are passing a corrupt or invalid file to the function. – Neil Oct 18 '18 at 13:12
  • @Neil I've try with many file, a file can work well one time, and crash the next time (in same run or different run). – A.Pissicat Oct 18 '18 at 13:36
  • Yes, the C++ runtime can generate this diagnostic. It cannot be caught, it is not thrown as an exception and will failfast the entire process. Technically the C++ code can [use this function](https://msdn.microsoft.com/en-us/library/a9yf33zb.aspx) to change that behavior, but it is not like that will produce a better outcome. It is always a programming bug and exceptions don't fix bugs. – Hans Passant Oct 18 '18 at 15:22

0 Answers0