I'm trying to write a .Net application that interacts and "probes" the "SAP Front End" client UI. For that aim Iu2019m using the "Scripting API" technology by referencing the SAPFEWSELib COM object from my .Net application.
Problem Description: I'm communicating with "SAP Front End" client application from my Net code (by calling the COM object SAPFEWSELib ).The code among other things, registers to all available SAP session events ( Focus, Changed etc..) for the current session. For a while everything work as expected - I receive notifications of the events in the callback and I'm able to successfully use the Com Scripting API. But after a while I stop getting the events, and when I try to unregister\register again I receive the following exception:
System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
at System.Runtime.InteropServices.ComTypes.IConnectionPoint.Unadvise(Int32 dwCookie)
at SAPFEWSELib.ISapSessionEvents_EventProvider.remove_Change(ISapSessionEvents_ChangeEventHandler )
at SAPFEWSELib.ISapSessionEvents_Event.remove_Change(ISapSessionEvents_ChangeEventHandler )
a. This behavior is always reproduced. (This was tested in various machines).
b. I still manage to successfully call the COM object for API that is not related to events, even when events stop arriving.
c. The application uses the STA model (single-thread apartment).
d. I'm using "SAP Front End" client with patch 13. (Trail version NetWeaver 7.01 server)
Does anyone have a clue about why is this occurring? Has anyone run into similar problems?