0
votes

I'm having an issue with the SAP NCO 3.0 library, but can't even log in to their website to post on their forums because of a server error of 500.

The issue is that I have an RFCServer set up to receive iDocs from a SAP system (<i>IDOC_INBOUND_ASYNCHRONOUS</i> for the function table) which receives an iDoc and does some processing.

When the server is in the process of receiving a large amount of files and the user shuts down the RFCServer, the SAP library throws an <i>AccessViolationException</i> causing the entire application to crash.

I've tried dressing up the encapsulated Shutdown method with the [HandleProcessCorruptedStateExceptions] Attribute, but the exception still isn't caught.

The code is :

    public void Shutdown()
    {
        try
        {
            if (_SapServer != null)
            {
                _SapServer.Shutdown(false);
            }
        }
        catch (Exception e)
        {
            throw new Exception("Error stopping server", e);
        }

        if (_SapServer != null)
        {
            _SapServer.RfcServerError -= OnRfcServerError;
            _SapServer.RfcServerApplicationError -= OnRfcServerApplicationError;
            _SapServer.RfcServerStateChanged -= OnRfcServerStateChanged;
            _SapServer.TransactionIDHandler = null;
        }
    }

I've swapped out Shutdown(true) for Shutdown(false), which tells it to abort running calls.

The stack trace is :

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

at STRCV(Byte* , Char* , Int32* , Int32* , Int32* , Int32* , Int32* , Int32* )
at SAP.Middleware.Connector.CpicConnection.CpicReceive(Int32 timeout)
at SAP.Middleware.Connector.RfcConnection.Accept(Int32 timeout)
at SAP.Middleware.Connector.RfcConnection.RfcServerWorkerThreadProc(Object rfcConnObj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()

at System.Threading.ThreadPoolWorkQueue.Dispatch()

in sapnco_utils.dll

If anyone could point me in the right direction, as I've basically come to a dead end with this.

1
You cannot read or write files on the server. Make sure client paths are on a driver that the user/client has privilege to read/write. A client connecting to a server has GUEST privilege. if the server is executing any programs on the server the programs have to be set to run as admin so the guests can execute the programs. - jdweng
The server is running as an administrator + the user the process is running as has full control of the directory. - Tom Johnson
I sometimes see this error message when an exception get stuck in an endless loop spawning additional error messages. The error message " "Attempted to read or write protected memory" occurs for 2 reasons 1) You are running unmanaged code (like a c++) from c# 2) You run out of memory on the stack. This happens when a recursive method is called continuously or when you get an exception that call another exception and eventually runs out of memory. - jdweng

1 Answers

0
votes

Bit late, but for anyone who has the same issue, the fix is the make sure the general configuration parameter for keeping CPIC responses alive is set to false.

GeneralConfiguration.CPICKeepAliveResponse = false;

Seems that if you ever end up in the scenario where you're stopping the SAP Server while receiving a connection it will sometimes throw this exception (probably something to do with the underlying connection being persisted). Setting this to false fixed the issue.