Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

NCO 3 An unhandled microsoft .net framework exception occurred in w3wp.exe

Hi Experts,

I have .Net a webservice  to post Goods Movement in SAP using NCO 3.0 it works fine and data is reflected in SAP after execution of this service

But 10 to 15 minutes  after executing this webservice I get an exception (A Just in Time debugger window appars if visual studio installed in the machine where this web service is hosted otherwise I can see it in the event log)

an unhandled microsoft .net framework exception occurred in w3wp.exe [8920]

below is the stack trace

Application: w3wp.exe

Framework Version: v4.0.30319

Description: The process was terminated due to an unhandled exception.

Exception Info: System.InvalidOperationException


   at System.ThrowHelper.ThrowInvalidOperationException(System.ExceptionResource)

   at System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator[[System.__Canon, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext()

   at SAP.Middleware.Connector.RfcSessionManager.UpdateSessions(System.Object)

   at System.Threading._TimerCallback.TimerCallback_Context(System.Object)

   at System.Threading.ExecutionContext.runTryCode(System.Object)

   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)

   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)

   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)

   at System.Threading._TimerCallback.PerformTimerCallback(System.Object)

Below is my code snippet

SAPConfig sapCfg = new SAPConfig();
    catch { }

    SapRfcDestination = RfcDestinationManager.GetDestination(Destination);
    RfcRepository SapRfcRepository = null;
    SapRfcRepository = SapRfcDestination.Repository;  

    IRfcFunction bapiCommit = SapRfcRepository.CreateFunction("BAPI_TRANSACTION_COMMIT");
    IRfcFunction function = SapRfcRepository.CreateFunction("BAPI_GOODSMVT_CREATE");
    string tempdate  = Utilities.ToSAPDateFormat(postingdate);
    IRfcStructure MovHder = function.GetStructure("GOODSMVT_HEADER");
    MovHder.SetValue("PSTNG_DATE", tempdate);
    MovHder.SetValue("REF_DOC_NO", refDocNo);  //delivery note
    IRfcStructure MovCode = function.GetStructure("GOODSMVT_CODE");
    MovCode.SetValue("GM_CODE", "01");  //receipt against PO
    IRfcTable tblitems = function.GetTable("GOODSMVT_ITEM");

tblitems.SetValue("PO_ITEM", "10");
tblitems.SetValue("PLANT", "9000");
tblitems.SetValue("STGE_LOC", "0001");
tblitems.SetValue("ENTRY_QNT", "1");
tblitems.SetValue("STCK_TYPE", ""); //blank unrestricted X quality

tblitems.SetValue("MOVE_TYPE", "101");
tblitems.SetValue("MVT_IND", "B");  // for purchase order
tblitems.SetValue("VENDOR", VendorCode);
tblitems.SetValue("PO_NUMBER", PoNo);     

    RfcSessionManager.BeginContext(SapRfcDestination);  //begins session since commit and and goods movement bapi should be called in a session
    function.Invoke(SapRfcDestination); //execute goods mvt bapi  bapi
    bapiCommit.Invoke(SapRfcDestination); //execute commit bapi
    IRfcStructure headRetorno = function.GetStructure("GOODSMVT_HEADRET");
    IRfcTable rettable = function.GetTable("RETURN");
    materialDoc = headRetorno.GetValue("MAT_DOC").ToString(); //headRetorno["MAT_DOC"].ToString();
    //set return parameters to the caller
    statuscode = "S";
    statusmsg = materialDoc;
    errormsg = "Posted";

catch (Exception outerexp)
//set return parameters to the caller
    statuscode = "E";
    statusmsg = "";
    errormsg = outerexp.Message;;
        RfcSessionManager.EndContext(SapRfcDestination);  //end the context
    catch { }

        RfcDestinationManager.UnregisterDestinationConfiguration(sapCfg);  //added this code to test wether registered connection causes this error
        sapCfg = null;
    catch { }

Former Member
Former Member replied

I changed the refernce from NCO to and Not experiencing this issue after this change

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question