C#Web API中的AccessViolation异常

时间:2015-08-14 11:55:23

标签: c# visual-studio asp.net-web-api access-violation saprfc

通过C#Web API访问SAP RFC时遇到错误。以下是详细信息: 我能够从SAP RFC获得存储在out param中的响应,但是在将其返回给我的函数时抛出异常。这是代码:

    internal string FromBupaToBupaGuid(string sBupa)
    {
        using (SAPContext db = new SAPContext(base.GetConnectStringForRfcUser()))
        {
            ERPConnect.LIC.SetLic(base.GetLicenseKey());
            string sBupaGuid;
            SAPContext.MESSAGESTable mESSAGESTable = new SAPContext.MESSAGESTable();
            sBupa = ToBupa(sBupa);
            db.IST_GET_BPARTNER_GUID(out sBupaGuid, sBupa, mESSAGESTable);

            return sBupaGuid;
        }
    }

以下是异常信息:

System.AccessViolationException was unhandled
  HResult=-2147467261
  Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
  Source=ERPConnect40
  StackTrace:
       at ERPConnect.RFCAPI.RfcCallReceiveExt(Int32 handle, Int32 hSpace, String FuncName, StringBuilder Exception)
       at ERPConnect.R3Connection.Ping()
       at ERPConnect.Linq.ERPDataContext.Dispose(Boolean disposing)
       at ERPConnect.Linq.ERPDataContext.Dispose()

注意:代码中没有问题,因为它安静的旧代码在我早期的机器(Windows 7 + VS 2012)中工作正常,现在正在使用Windows 8.1。

我已经尝试过了:

  • 选中/取消选中两者 - 工具>选项>调试>一般>抑制模块负载的JIT优化(仅限管理)
  • Visual Studio 2012和2013都试过
  • .Net framework version 4.5.2

请帮忙。

2 个答案:

答案 0 :(得分:0)

I am getting the same issue when trying to use standard BAPI function using the connection.CreateFunction() method. It seems to be occurring randomly as well.

RFCFunction funcModify = _r3Connection.CreateFunction("BAPI_ALM_NOTIF_DATA_MODIFY");
                funcModify.Exports["NUMBER"].ParamValue = notifNo.PadLeft(12,'0');

I have posted a ticket with theobald software, owners of ERPconnect. Will post any useful info if i manage to get to to work.

答案 1 :(得分:0)

对于我的情况,问题与 SystemWow 文件夹中缺少 librfc32.dll 有关,我通过放置两个librfc dll解决了问题:一个用于32位和另一个是 Windows / Systems 文件夹中的64位。

我已经引用了以下链接,它包含有关库位置和dll的必需信息:

https://my.theobald-software.com/index.php?/Knowledgebase/Article/View/71/9/theobald--products-in-a-64-bit-environment

希望这有助于他人。