private void LoadDynamicLibraries()

in csharp/NativeUtils/ResourceLoader.cs [960:1021]


        private void LoadDynamicLibraries(string deploymentPath)
        {
            // On Linux out deployment path is not searched to resolve library interdependencies,
            // we solve this by using lazy binding though this is not a great solution
            bool useLazyBinding = _dlCount > 1;
            int numLoaded = 0;
            bool loadedLeastOne;
            DlException exception = null;
            // Remembers "Current directory", to be restored on exit. Part of the workaround for Mac OSX.
            string oldCwd = null;

            // This method works as a workaround for Mac OSX at least
            if (OS.IsDarwin)
            {
                oldCwd = Directory.GetCurrentDirectory();
                Directory.SetCurrentDirectory(deploymentPath);
            }

            try
            {
                do
                {
                    loadedLeastOne = false;
                    foreach (var resource in _resources)
                        if (resource.IsDll && IntPtr.Zero == resource.DlHandle)
                        {
                            // Workaround, load from the current dir on OSX
                            var path = OS.IsDarwin ? resource.Filename : resource.FullPath(deploymentPath);
                            Dbg("last.dllExisted", File.Exists(path));
                            Dbg("last.dllHadLock", null != resource.File);
                            Dbg("last.dllsLoaded", numLoaded);

                            if (LogLevelLeast(DBG))
                                Log($"Loading DLL#{numLoaded + 1}: {path} , exists: {File.Exists(path)}, hasLockFile: {null != resource.File}");

                            exception = null;
                            if (IntPtr.Zero == (resource.DlHandle = OS.LoadNativeLibrary(path, useLazyBinding)))
                            {
                                string errorText = OS.LastDlErrorText();
                                if (LogLevelLeast(DBG))
                                    Log($"LoadLibrary Exception : {errorText}");
                                exception = new DlException($"{path} : {errorText}");
                            }
                            else
                            {
                                Log("ook");
                                ++numLoaded;
                                loadedLeastOne = true;
                                Dbg("last.dllsLoaded", numLoaded);
                            }
                        }
                } while (loadedLeastOne);
            }
            finally
            {
                if (null != oldCwd)
                    Directory.SetCurrentDirectory(oldCwd);
            }

            if (null != exception)
                throw exception;
        }