cancel
Showing results for 
Search instead for 
Did you mean: 

SAP.Middleware.Connector

0 Kudos

It's my first time trying to connect on SAP system and fetch data.

Here is my attempt below(AppServerHost,User and Password data is removed in the screenshot).

Why there is exception, when all parameters are fulfilled.

Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert
0 Kudos

I can't really read the screenshot (in particular, it's not clear to me, which object is null).

Can you provide the code as well as the exception callstack in two text comments? (Makes it easier to copy&paste, if we need to try out the code sample ourselves...)

0 Kudos

Hi Ulrich, here is the code:

                    try
            {

                RfcConfigParameters configParms = new RfcConfigParameters();
                configParms.Add(RfcConfigParameters.AppServerHost, "");
                configParms.Add(RfcConfigParameters.SystemNumber, "00");
                configParms.Add(RfcConfigParameters.Client, "100");
                configParms.Add(RfcConfigParameters.User, "");
                configParms.Add(RfcConfigParameters.Password, "");
                configParms.Add(RfcConfigParameters.Language, "EN");
                configParms.Add(RfcConfigParameters.PoolSize, "5");


                RfcDestination destination = RfcDestinationManager.GetDestination(configParms);

                RfcRepository repository = destination.Repository;

                IRfcFunction rfcFunction = repository.CreateFunction("Z_***_STAFF_TIME");

                // Set input parameters if required
                // rfcFunction.SetValue("ParameterName", parameterValue);

                // Invoke the RFC function
                rfcFunction.Invoke(destination);

                // Get the output parameters or result
                //var outPutValue = rfcFunction.GetString("OutputParameterName");


                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
System.NullReferenceException<br>  HResult=0x80004003<br>  Message=Object reference not set to an instance of an object.<br>  Source=sapnco<br>  StackTrace:<br>   at SAP.Middleware.Connector.RfcConfigParameters.LoadConfiguration()

> SAPTestNetConnector.exe!SAPTestNetConnector.Program.Main(string[] args) Line 23 C#

-Target Framework: .NET Framework 4.8.1

- Output type: Console Application

Surprisingly I manage to get the data I want, but in output window I notice the exception is still there:

Exception thrown: 'System.NullReferenceException' in sapnco.dll
Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert
0 Kudos

PS: for some strange reason, I never got a mail notification for your update...

Sorry, took a while before I found this accidentally... 😞

Accepted Solutions (1)

Accepted Solutions (1)

Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert

Ok, I know what it is: the Microsoft debugger automatically stops, when a NullReferenceException is thrown, no matter whether later some code catches and handles it or not.

RfcConfigParameters.LoadConfiguration() first tests, whether the program runs as a standalone/desktop .NET Application or as a Web Application inside IIS. Unfortunately, this is possible only by some Microsoft .NET API, which throws a NullReference when not running in IIS... 😞

But the exception is then caught internally in NCo, and the code branch for "standalone .NET Application" is then executed and everything continues normally.

So basically: just ignore the exception, everything works fine! You can disable the feature that the .NET debugger stops at that exception like Sandra has done here:

https://answers.sap.com/questions/13508257/getdestination-returns-object-reference-not-set-to.html

(By the way, a quick search on answers.sap.com would have found that solution and saved you the trouble of creating a new question for an already known problem...)

Answers (0)