17

While coding a console app, I'm using an SAP DLL. I'm getting the following error when trying to add an SAP object:

A debugger is attached to but not configured to debug this unhandled exception. To debug this exception detach the current debugger.

Code:

SAPbobsCOM.GeneralService oGeneralService = oCmpSrv.GetGeneralService("WEPPAGE");
SAPbobsCOM.GeneralData oGeneralData = (SAPbobsCOM.GeneralData)oGeneralService.GetDataInterface(di.GeneralServiceDataInterfaces.gsGeneralData);
oGeneralData.SetProperty("U_WebId", "1");
try
{
    oGeneralService.Add(oGeneralData);
}
catch (Exception e)
{
    Logger.WriteLog("Error Add object " + e.Message);
}

Although the code is wrapped with try&catch, the IDE crashes.

enter image description here

After many searches and suggestions around the web, which did not helped, I came across this post and applied the suggested solution and enabled native code debugging under the project properties debug tab.

enter image description here

The result of ticking this option was that instead of letting me debug the unknown error, the exception just "disappeared" and the code runs with no interference.

Questions

  1. Why does the exception disappears and not debugged?
  2. Is it possible to have a different workaround for this problem since enabling the native code debugging is slowing down the app by 10x and not a real solution this problem.
Urik
  • 1,598
  • 3
  • 19
  • 37
  • Any occurences in logs after enabling native code debugging? Or Logger did not log anything? – mwilczynski May 06 '15 at 14:25
  • @m_wilczynski Nothing in the logfile, couldn't get any info beyond what I've written here... – Urik May 06 '15 at 14:47
  • Maybe Logger is throwing an exception here? It would make little sense but it's not getting catched as it's in a catch block itself? – mwilczynski May 06 '15 at 14:49
  • @m_wilczynski Logger is working fine in many other places in the code before reaching that point. – Urik May 06 '15 at 14:50

1 Answers1

15

Although the code is wrapped with try&catch, the IDE crashes

No, the WER dialog shows that it is your program that crashed, not the IDE. Not your code, OBServerDLL is a SAP component. And given the nature of the crash, using try/catch is not going to be able to catch this exception, it occurs on a worker thread inside the SAP code.

Do keep in mind that the crash reason is very nasty, exception code c0000005 is the equivalent of an AccessViolationException. The usual reason for it is memory corruption. Never catch an exception like that, your program cannot meaningfully continue operating.

Why does the exception disappears and not debugged?

This is certainly not supposed to happen, very unhealthy. AVEs do tend to be rather random, memory corruption does not guarantee a crash. Keep in mind that when it does occur while you are debugging then you still can't find out anything about the reason, you don't have the source code for the OBServerDLL.

enabling the native code debugging is slowing down the app by 10x

That's quite unlikely, unless the native code is throwing exceptions at a very high rate. Something you can easily see in the Output window. What it does do is slow-down the startup of your debug session. The debugger will try to find PDBs for all the native executables, it isn't going to find anything at the Microsoft Symbol Server for SAP code. Simplest way to avoid that delay is using Tools > Options > Debugging > Symbols, untick the "Microsoft Symbols Servers" option.

This question at the SAP support forums would be somewhat comparable. Also the best place to find help with a problem like this. Albeit that it is likely you need support from a SAP escalation engineer, he'll need a small repro project and a minidump of the crashed process.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Although it didn't solve my problem, this answer includes lots of useful insights. I had to switch back to X86 in order to avoid the app crash and I'll hope SAP will fix the dll for X64. – Urik May 14 '15 at 08:54