Ejemplo n.º 1
0
        public IntPtr LoadLibrary(string fileName, string platformName = null)
        {
            fileName = FixUpLibraryName(fileName);
            lock (syncLock)
            {
                if (!loadedAssemblies.ContainsKey(fileName))
                {
                    if (platformName == null)
                    {
                        platformName = SystemManager.GetPlatformName();
                    }

                    Logger.TraceInformation("Current platform: " + platformName);


                    Console.WriteLine($"Try to load {fileName}");

                    var dllHandle = CheckCustomSearchPath(fileName, platformName);
                    if (dllHandle == IntPtr.Zero)
                    {
                        dllHandle = CheckExecutingAssemblyDomain(fileName, platformName);
                    }
                    if (dllHandle == IntPtr.Zero)
                    {
                        dllHandle = CheckCurrentAppDomain(fileName, platformName);
                    }
                    if (dllHandle == IntPtr.Zero)
                    {
                        dllHandle = CheckCurrentAppDomainBin(fileName, platformName);
                    }
                    if (dllHandle == IntPtr.Zero)
                    {
                        dllHandle = CheckWorkingDirecotry(fileName, platformName);
                    }
                    if (dllHandle == IntPtr.Zero)
                    {
                        dllHandle = logic.LoadLibrary(fileName);
                    }

                    if (dllHandle != IntPtr.Zero)
                    {
                        Console.WriteLine($"{fileName} loaded.");
                        loadedAssemblies[fileName] = dllHandle;
                    }
                    else
                    {
                        var errorMessage = string.Format("Failed to find library \"{0}\" for platform {1}.", fileName,
                                                         platformName);
                        Console.WriteLine(errorMessage);
                        throw new DllNotFoundException(errorMessage);
                    }
                }

                return(loadedAssemblies[fileName]);
            }
        }
Ejemplo n.º 2
0
        private IntPtr InternalLoadLibrary(string baseDirectory, string platformName, string fileName)
        {
            var fullPath  = Path.Combine(baseDirectory, Path.Combine(platformName, fileName));
            var localpath = Path.Combine(baseDirectory, fileName);

            if (File.Exists(fullPath))
            {
                return(logic.LoadLibrary(fullPath));
            }
            else if (File.Exists(localpath))
            {
                return(logic.LoadLibrary(localpath));
            }
            return(IntPtr.Zero);
        }
Ejemplo n.º 3
0
        private IntPtr InternalLoadLibrary(string baseDirectory, string platformName, string fileName)
        {
            var fullPath = Path.Combine(baseDirectory, Path.Combine(platformName, fileName));

            return(File.Exists(fullPath) ? logic.LoadLibrary(fullPath) : IntPtr.Zero);
        }