На данный момент я пытаюсь использовать разъем SAP .NET 3.1.5.0 в одном из моих консольных приложений C#. Я хотел бы получить данные из нашей системы SAP BW с помощью программы C#, используя запрос BW, который сохраняется в файле MDX. Но я не могу запустить программу. Я всегда получаю следующее сообщение об ошибке в строке 18 кода: < /p>
На данный момент я пытаюсь использовать разъем SAP .NET 3.1.5.0 в одном из моих консольных приложений C#. Я хотел бы получить данные из нашей системы SAP BW с помощью программы C#, используя запрос BW, который сохраняется в файле MDX. Но я не могу запустить программу. Я всегда получаю следующее сообщение об ошибке в строке 18 кода: < /p> [code] 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.
My program.cs code is the following: ====================================
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}");
// 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();