Example #1
0
        /// <summary>
        /// load dll which is in root path,and not kooboo dll
        /// </summary>
        /// <param name="extensiondlls"></param>
        public void LoadSpecificDlls(string extensiondlls)
        {
            var path = AppDomain.CurrentDomain.BaseDirectory;

            if (!string.IsNullOrEmpty(extensiondlls))
            {
                var extensionList = extensiondlls.Split(',').Distinct().ToList();
                foreach (var dll in extensionList)
                {
                    try
                    {
                        var filename = dll.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)
                            ? dll
                            : string.Format("{0}.dll", dll);

                        var filepath = Path.Combine(path, filename);
                        if (File.Exists(filepath))
                        {
                            var assembly = Assembly.Load(File.ReadAllBytes(filepath));

                            if (assembly != null && !Assemblies.Exists(ass => ass.FullName.Equals(assembly.FullName)))
                            {
                                Assemblies.Add(assembly);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
        }
Example #2
0
        public Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            var assemblyName = new AssemblyName(args.Name);
            var name         = assemblyName.Name;

            var assembly = Assemblies.Find(a =>
            {
                return(assemblyName.FullName == a.FullName);
            });

            if (assembly != null)
            {
                return(assembly);
            }

            var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            var path          = extensionFolders.Select(folder =>
            {
                var dllpath = Path.Combine(baseDirectory, folder, string.Format("{0}.dll", name));
                if (File.Exists(dllpath))
                {
                    return(dllpath);
                }

                return(string.Empty);
            }).FirstOrDefault();

            if (!string.IsNullOrEmpty(path))
            {
                assembly = Assembly.Load(File.ReadAllBytes(path));
                lock (_lockObj)
                {
                    if (!Assemblies.Exists(a => a.FullName == assemblyName.FullName))
                    {
                        Assemblies.Add(assembly);
                    }
                }
                return(assembly);
            }

            return(null);
        }