huysentruitw/SapNwRfc

SapServer Error Event Handler - unable to use

Closed this issue · 4 comments

I have been successfully using the SapServer functionality for quite a while, but haven't been able to handle errors in the connection. I'm handling the StateChange event which works as expected when the server is explicitly started, stopped, etc. However, if something breaks the connection on the SAP side (including forcing the disconnection in SMGW), the StateChange event doesn't fire. It does appear this is correct, but any attempt to handle the Error event immediately aborts my application.

I can add the Error handler at startup without issue. However, as soon as it fires, my application crashes and I'm unable to trap the exception. The exception looks something like this:

An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module.: 'Object reference not set to an instance of an object.'
Stack trace:
 ><Cannot evaluate the exception stack trace>

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

In the debugger, the offending thread shows Thread - [Managed to Native Transition]

So, it would seem this issue is off in un-managed code that I can't handle myself. I looked pretty closely at the RFC SDK documentation vs. the RfcInterop and I don't see any discrepancies.

These are the steps I can use to cause the issue:

  • Start up RFC server and register a handler for the Error event
  • In SAPGUI, in transaction SMGW, Goto -> Logged on Clients
  • Select the connection and Goto -> Logged on Clients -> Delete Client

Any input or help on how this event can be handled would be greatly appreciated.

Are you using this implementation 7fa7175 ?

No, that doesn't look exactly like what I have. I can try adding those changes see if it changes things.

I added that later in #53

That is what I needed. Error event is working now and will be very helpful. Thanks!