예제 #1
0
        /// <summary>
        /// 将domain程序集插入共享程序集
        /// </summary>
        private void DomainAssemblyInsertShareLib()
        {
            var assemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();

            foreach (var assembly in assemblies)
            {
                if (!BundleUtils.IsAssemblyBelongsFcl(assembly.GetName().Name))
                {
                    if (!BundleAssemblyProvider.CheckHasShareLib(assembly.FullName))
                    {
                        log.Debug(string.Format("框架关联共享程序集[{0}]!", assembly.GetName().Name));

                        BundleAssemblyProvider.AddShareAssembly(assembly.FullName, assembly);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 通过反射加载程序集
        /// </summary>
        /// <param name="assemblyFileName"></param>
        /// <returns></returns>
        private void LoadShareAssemblyByReflect(string assemblyFileName)
        {
            try
            {
                AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(assemblyFileName);
                if (!BundleAssemblyProvider.CheckHasShareLib(assemblyDefinition.FullName))
                {
                    Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().ToList()
                                        .FirstOrDefault(item => item.FullName == assemblyDefinition.FullName);

                    if (assembly == null)
                    {
                        if (BundleConfigProvider.OSGi_NET_IS_DEBUG_MODE)
                        {
                            assembly = Assembly.LoadFrom(assemblyFileName);
                        }
                        else
                        {
                            assembly = Assembly.Load(File.ReadAllBytes(assemblyFileName));
                        }
                    }

                    if (BundleConfigProvider.OSGi_NET_ALLTYPES_LOAD)
                    {
                        assembly.GetTypes();
                    }

                    log.Debug(string.Format("框架加载共享程序集[{0}]!", assembly.GetName().Name));

                    BundleAssemblyProvider.AddShareAssembly(assembly.FullName, assembly);
                }
            }
            catch (Exception ex)
            {
                log.Error(string.Format("加载共享程序集[{0}]时出现异常!", assemblyFileName), ex);
            }
        }