Skip to Content
avatar image
Former Member

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

Stack:

   at System.ThrowHelper.ThrowInvalidOperationException(System.ExceptionResource)

   at System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, 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();
try
{
   
    try
    {
        RfcDestinationManager.RegisterDestinationConfiguration(sapCfg);
    }
    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.Append();
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;;
   
}
finally
{
    try
    {
        RfcSessionManager.EndContext(SapRfcDestination);  //end the context
    }
    catch { }

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Feb 03, 2014 at 09:36 AM

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

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 05, 2014 at 12:54 AM

    Well, you shall avoid calling this section more than once:

    SAPConfig sapCfg = new SAPConfig();
    try
    {

        try
        {
            RfcDestinationManager.RegisterDestinationConfiguration(sapCfg);
        }
        catch { }     SapRfcDestination = RfcDestinationManager.GetDestination(Destination);

    Rather use the other variant of GetDestination():

    var par = new RfcConfigParameters();
    //config par here
    ....
    var dest = RfcDestinationManager.GetDestination(par);
    

    or call the RfcDestinationManager.RegisterDestinationConfiguration(sapCfg); only once when your application starts. Yet SapRfcDestination = RfcDestinationManager.GetDestination(Destination); can be called as many times you want.

    Add comment
    10|10000 characters needed characters exceeded

    • One of the option is

      1. var par = new RfcConfigParameters(); 
      2. //config par here 
      3. .... 
      4. var dest = RfcDestinationManager.GetDestination(par); 

      i.e. not using RegisterDestinationConfiguration(sapCfg) at all. Or

      1. RfcDestination getDestination(dest as string) {  
      2.     if (RfcDestinationManager.TryGetDestination(dest) == null) {  
      3.          IDestinationConfiguration _destConfig = new IDestinationConfigurationImplementation();  
      4.          RfcDestinationManager.RegisterDestinationConfiguration(_destConfig);  
      5.     }  
      6.     return RfcDestinationManager.GetDestination(dest);  
      7. }  

      see Experiences around the nCo 3.0 RfcDestinationMa... | SCN

      .... assuming "dest" is well known by the IDestinationConfigurationImplementation.