Я много искал и проверял в последние дни, но я не могу запустить программу. Я всегда получаю следующее сообщение об ошибке в строке 18 кода: < /p>
Код: Выделить всё
Error message at:
Line 18 => RfcDestinationManager.RegisterDestinationConfiguration(new MyDestinationConfig());
=============================================================================================
Windows Version: 10.0.22621
.NET 8.0.11
Exception thrown: 'System.TypeInitializationException' in sapnco.dll
An error occurred: The type initializer for 'SAP.Middleware.Connector.RfcDestinationManager' threw an exception.
Inner exception: The type initializer for 'SAP.Middleware.Connector.RfcConfigParameters' threw an exception.
Innermost exception: Could not load type 'System.ServiceModel.Activation.VirtualPathExtension' from assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
Код: Выделить всё
using SAP.Middleware.Connector;
using System.Runtime.InteropServices;
namespace SAPBW_MDX_Example
{
class Program
{
static void Main(string[] args)
{
try
{
var version = Environment.OSVersion.Version;
Console.WriteLine($"Windows Version: {version.Major}.{version.Minor}.{version.Build}");
Console.WriteLine(RuntimeInformation.FrameworkDescription);
RfcDestinationManager.RegisterDestinationConfiguration(new MyDestinationConfig());
RfcDestination destination = RfcDestinationManager.GetDestination("mySAPdestination");
RfcRepository repository = destination.Repository;
IRfcFunction mdxFunction = repository.CreateFunction("BAPI_MDX_EXECUTE");
// Read the MDX query from the file
string mdxQuery = File.ReadAllText(@"C:\Daten\Q014.mdx");
mdxFunction.SetValue("MDX_QUERY", mdxQuery);
// Execute the MDX query
mdxFunction.Invoke(destination);
// Retrieve the result
IRfcTable resultTable = mdxFunction.GetTable("RESULT");
// Process the result
foreach (IRfcStructure row in resultTable)
{
Console.WriteLine($"Product Category: {row.GetString("PRODUCT_CATEGORY")}, Sales: {row.GetDecimal("SALES")}, Quantity: {row.GetDecimal("QUANTITY")}");
}
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
if (ex.InnerException != null)
{
Console.WriteLine("Inner exception: " + ex.InnerException.Message);
if (ex.InnerException.InnerException != null)
{
Console.WriteLine("Innermost exception: " + ex.InnerException.InnerException.Message);
}
}
}
}
}
public class MyDestinationConfig : IDestinationConfiguration
{
public bool ChangeEventsSupported() => false;
public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged;
public RfcConfigParameters GetParameters(string destinationName)
{
if ("mySAPdestination".Equals(destinationName))
{
RfcConfigParameters parameters = new RfcConfigParameters();
parameters.Add(RfcConfigParameters.Name, "mySAPdestination");
parameters.Add(RfcConfigParameters.AppServerHost, "xxx.xxx.41.158");
parameters.Add(RfcConfigParameters.SystemNumber, "00");
parameters.Add(RfcConfigParameters.User, "strUserID");
parameters.Add(RfcConfigParameters.Password, "strPassword");
parameters.Add(RfcConfigParameters.Client, "200" );
parameters.Add(RfcConfigParameters.Language, "EN");
return parameters;
}
else{
return null;
}
}
}
}
Код: Выделить всё
< /code>
my .csproj file выглядит так: < /p>
Exe
net8.0-windows10.0.22621
enable
enable
Debug
x64
bin\Debug\
libs\sapnco.dll
libs\sapnco_utils.dll
frank.
Подробнее здесь: https://stackoverflow.com/questions/793 ... -1-5-0-x64
Мобильная версия