cancel
Showing results for 
Search instead for 
Did you mean: 

SAP RFC Could not connect in .NET

cpavel_garcia
Explorer
0 Kudos

I've created a console application with .NET Framework 3.1, connector 3.0 64 bits from here

https://support.sap.com/en/product/connectors/msnet.html

and when I tried to run this code I had an error:

RfcConfigParameters rfcPar = new RfcConfigParameters();
rfcPar.Add(RfcConfigParameters.AppServerHost, "xxxx");
rfcPar.Add(RfcConfigParameters.Client, "xxxxx");
rfcPar.Add(RfcConfigParameters.User, "xxxx");
rfcPar.Add(RfcConfigParameters.Password, "xxxxx");
rfcPar.Add(RfcConfigParameters.SystemNumber, "xxxxx");
rfcPar.Add(RfcConfigParameters.Language, "xxxxx");
RfcDestination dest2 = RfcDestinationManager.GetDestination(rfcPar);
try
{
dest2.Ping();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
System.TypeInitializationException: 'The type initializer for 'SAP.Middleware.Connector.RfcConfigParameters' threw an exception.'

TypeLoadException: Could not load type 'System.ServiceModel.Activation.VirtualPathExtension' from assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Anyone could help me? Thanks!

View Entire Topic
david_burg
Participant
0 Kudos

Per the exception content a .NET Framework 4.x is loaded. Could you double-check which .NET Framework version your console application project is targeting? Also check that the NCo library version you installed is matching the .NET Framework version you are targetting.