/// <summary>
        /// Add a managed library to the load context.
        /// </summary>
        /// <param name="library">The managed library.</param>
        /// <returns>The builder.</returns>
        public AssemblyLoadContextBuilder AddManagedLibrary(ManagedLibrary library)
        {
            ValidateRelativePath(library.AdditionalProbingPath);

            _managedLibraries.Add(library.Name.Name, library);
            return(this);
        }
Esempio n. 2
0
        private bool SearchForLibrary(ManagedLibrary library, out string path)
        {
            // 1. Search in base path
            foreach (var ext in PlatformInformation.ManagedAssemblyExtensions)
            {
                var local = Path.Combine(_basePath, library.Name.Name + ext);
                if (File.Exists(local))
                {
                    path = local;
                    return(true);
                }
            }

            // 2. Check for in _basePath + app local path
            var localFile = Path.Combine(_basePath, library.AppLocalPath);

            if (File.Exists(localFile))
            {
                path = localFile;
                return(true);
            }

            // 3. Search additional probing paths
            foreach (var searchPath in _additionalProbingPaths)
            {
                var candidate = Path.Combine(searchPath, library.AdditionalProbingPath);
                if (File.Exists(candidate))
                {
                    path = candidate;
                    return(true);
                }
            }

            path = null;
            return(false);
        }