nunomaia / NwRfcNet

An easy way of making SAP RFC calls from .NET Core
Apache License 2.0
95 stars 28 forks source link

can you support automatic load of SAP NetWeaver RFC Library DLL? #32

Closed sx212 closed 4 years ago

sx212 commented 4 years ago

can you support automatic load of SAP RFC Native Library DLL? such as : win64>icudt50.dll/icuin50.dll/icuuc50.dll/libicudecnumber.dll/libsapucum.dll/sapnwrfc.dll linux64>libicudata.so.50/libicudecnumber.so/libicui18n.so.50/libicuuc.so.50/libsapnwrfc.so/libsapucum.so

nunomaia commented 4 years ago

Sorry, I’m lost in your issue. Libsapnwrfc is load by NwRfcNet, other libs are directly by Libsapnwrfc. What is your issue exactly ?

sx212 commented 4 years ago

I hope to automatically load native DLL according to different platforms; code example: internal class PlatformDlls { public string Path { get; set; } public string[] DllNames { get; set; } }

    static UnsafeNativeMethods()
    {
        PlatformDlls libraryInfo = GetNativeLibraryInfo();
        var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
        foreach (var dll in libraryInfo.DllNames)
        {
            var dllPath = Path.Combine(path, "Native", libraryInfo.Path, dll);
            NativeLibrary.Load(dllPath);
        }
    }

    private static PlatformDlls GetNativeLibraryInfo()
    {
        PlatformDlls platformDlls = new PlatformDlls();
        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
            && (RuntimeInformation.ProcessArchitecture == Architecture.X64))
        {
            platformDlls.Path = "Win64";
            platformDlls.DllNames = new[] {
            "icudt50.dll",
            "icuin50.dll",
            "icuuc50.dll",
            "libicudecnumber.dll",
            "libsapucum.dll",
            "sapnwrfc.dll"
        };
        }
        else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
            && (RuntimeInformation.ProcessArchitecture == Architecture.X86))
        {
            platformDlls.Path = "Win32";
            platformDlls.DllNames = new[] {
            "icudt50.dll",
            "icuin50.dll",
            "icuuc50.dll",
            "libicudecnumber.dll",
            "libsapucum.dll",
            "sapnwrfc.dll"
        };
        }
        else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
            && (RuntimeInformation.ProcessArchitecture == Architecture.X64))
        {
            platformDlls.Path = "Linux64";
            platformDlls.DllNames = new[]
            {
            "libicudata.so.50",
            "libicudecnumber.so",
            "libicui18n.so.50",
            "libicuuc.so.50",
            "libsapnwrfc.so",
            "libsapucum.so"
        };
        }
        else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
        {
            platformDlls.Path = "OSX";
            platformDlls.DllNames = new[] {
            "libicudata.50.dylib",
            "libicudecnumber.dylib",
            "libicui18n.50.dylib",
            "libicuuc.50.dylib",
            "libsapnwrfc.dylib",
            "libsapucum.dylib"
        };
        }
        else
        {
            throw new Exception("Unsupported OSPlatform, can't locate sapnwrfc library.");
        }

        return platformDlls;
    }
nunomaia commented 4 years ago

This issue isn't related to paths and environment variable LD_LIBRARY_PATH ? SO’s tries to load library in defined folders. In Linux searches for libraries in folder application folder and folders defined in LD_LIBRARY_PATH. Do you get a particular error when using this library ? I have made a test and Linux and libraries where load properly. I have placed all libraries in the same folder.

Output from "ls -la" command in linux

-rw-r--r--. 1 usert usert 199168 Jul 31 20:24 CommandLine.dll -rw-rw-r--. 1 usert usert 1337 Nov 16 16:51 dev_rfc.trc -rw-r--r--. 1 test test 20788500 Nov 16 16:48 libicudata.so.50 -rw-r--r--. 1 test test 84766 Nov 16 16:48 libicudecnumber.so -rw-r--r--. 1 test test 12380128 Nov 16 16:48 libicui18n.so.50 -rw-r--r--. 1 test test 8705144 Nov 16 16:48 libicuuc.so.50 -rw-r--r--. 1 test test 8855319 Nov 16 16:48 libsapnwrfc.so -rw-r--r--. 1 test test 1060965 Nov 16 16:48 libsapucum.so -rw-r--r--. 1 usert usert 23552 Nov 16 15:20 NwRfcNet.dll -rw-r--r--. 1 usert usert 7004 Nov 16 15:20 NwRfcNet.pdb -rw-r--r--. 1 usert usert 1332 Nov 16 15:21 NwRfcNet.Sample.deps.json -rw-r--r--. 1 usert usert 14336 Nov 16 15:21 NwRfcNet.Sample.dll -rw-r--r--. 1 usert usert 2992 Nov 16 15:21 NwRfcNet.Sample.pdb -rw-r--r--. 1 usert usert 154 Nov 16 15:21 NwRfcNet.Sample.runtimeconfig.json

sx212 commented 4 years ago

well, i will try it, thanks.

nunomaia commented 4 years ago

If the problem persists please let me know and detail your environment