cancel
Showing results for 
Search instead for 
Did you mean: 

Problems porting a DI-API web-based program from SAP9.2 to SAP10

ccsa
Explorer
0 Kudos
187

Hello experts:

We did some time ago a C# WebApi that allows a sales person to do their work using a mobile phone. This WebApi was developed for SAP9.2 and was working for more than 3 years without problems.

Recently, we migrated to SAP10, so we took the Xamarin solution, changed the DI-API references, recompiled it and updated it in IIS. No code changes were made.

But the WebApi crash from time to time. Windows event logger says that "A process serving application pool 'aaa.com' suffered a fatal communication error with the Windows Process Activation Service. The process id was '****'. The data field contains the error number." (this code is 5011). This is linked with a w3wp.exe process error, that stops executing, and further investigation found this system exception: "Unhandled exception at 0x00007ffb3a36daf2 in w3wp.exe: 0xC0000005: Access violation reading location 0xffffffffffffff".

We don't know why this is happening. The code is the same, It looks like the problem comes when a document is added to SAP (example code)

                if (!asDraft)
                    deliverySAP = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes);
                else
                {
                    deliverySAP = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts);
                    deliverySAP.DocObjectCodeEx = ((int)SAPbobsCOM.BoObjectTypes.oDeliveryNotes).ToString();
                }

                deliverySAP.CardCode = delivery.cardCode;
                if (!string.IsNullOrWhiteSpace(delivery.cardName))
                    deliverySAP.CardName = delivery.cardName;

                deliverySAP.DocDueDate = delivery.docDueDate;
                deliverySAP.DocDate = delivery.docDate;

                if (delivery.discPrcnt > 0)
                    deliverySAP.DiscountPercent = delivery.discPrcnt;
                if (delivery.docTotal > 0)
                    deliverySAP.DocTotal = delivery.docTotal;

                //Adding new lines
                try
                {
                    if (!UpdateDeliveryNewLines(oCompany, deliverySAP, delivery.lines, true, asDraft))
                        _error = "-e003|Error adding lines.";
                } catch (Exception ex)
                {
                    _error = "-ex00|" + ex.Message;
                }

                if (string.IsNullOrWhiteSpace(_error))
                {
                    iError = 0;

                    try
                    {
                        iError = deliverySAP.Add();
                        
                        if (iError != 0)
                        {
                            oCompany.GetLastError(out iError, out _error);
                            _error = iError.ToString() + ": " + _error;
                        }
                        else
                        {
                            _error = oCompany.GetNewObjectKey();
                            delivery.Id = _error;
                            _error = GetDeliveryDocNum(oCompany, _error, asDraft);
                            delivery.docNum = _error;
                        }
                    }
                    catch (Exception ex)
                    {
                        _error = "-ex00|" + ex.Message;
                    }
                }
            }

            deliverySAP = null;

We found that w3wp.exe process memory starts at 230MB, and when oCompany is logged, it raises to 400MB. Then, we keep logged the oCompany for 3 minutes if no other operation is made, then we logged out user and dispose the oCompany, but the rest of time, there is one and only oCompany active.

But every operation, every WebApi call increased the RAM usage by 12Mb or so, an it keep rising until w3wp.exe crashes... or this is what we think. I added this at the end of the task, before setting document or recordset variable to null, to see if it will prevent it to crash:

System.Runtime.InteropServices.Marshal.ReleaseComObject(deliverySAP);

But we only reduced memory usage to +2MB per call.

We looked for an answer everywhere, from those "memory leaks" errors, any DI-API changes from 9.2 to 10, ways to "reset" the WebApi in IIS when no-one is working... We're not sure if it's a memory problem or what. The WebApi crashes and we can't find a way to fix this. As I mentioned before, this WebApi was working well for several years, it was tested A LOT, and no fix was needed since two years ago.

So, please, any help will be appreciated. Thank you

Accepted Solutions (0)

Answers (0)