public static void RegisterWithBuilderFromPath(ContainerBuilder builder, AppDomain currentDomain, EnumRegistrationType enumRegistrationType) { List<Assembly> vuelingAssembliesList = new List<Assembly>(); Assembly[] vuelingAssembliesArray; customRegistration(builder); List<Assembly> assemblies = currentDomain.GetAssemblies().ToList<Assembly>(); var loadedAssemblies = currentDomain.GetAssemblies().ToList(); var loadedPaths = loadedAssemblies.Select(a => a.Location).ToArray(); var referencedPaths = Directory.GetFiles(currentDomain.BaseDirectory, "*.dll"); var toLoad = referencedPaths.Where(r => !loadedPaths.Contains(r, StringComparer.InvariantCultureIgnoreCase)).ToList(); toLoad.ForEach(path => loadedAssemblies.Add(currentDomain.Load(AssemblyName.GetAssemblyName(path)))); foreach (var referencedAssembly in toLoad) { assemblies.Add(Assembly.LoadFrom(referencedAssembly)); } foreach (var assembly in assemblies.Distinct()) { if (assembly.GetName().Name.ToLower().Contains("vueling")) vuelingAssembliesList.Add(Assembly.Load(assembly.GetName().Name)); } vuelingAssembliesArray = vuelingAssembliesList.ToArray<Assembly>(); if (enumRegistrationType == EnumRegistrationType.justWithDecoratedClasses) RegisterAssemblyTypesWithDecoratedClasses(builder, vuelingAssembliesArray); else RegisterAssemblyTypes(builder, vuelingAssembliesArray); }
public IEnumerable<TypeWrapper> ListLoadedTypes(AppDomain appDomain) { if (appDomain == null) throw new ArgumentNullException("appDomain"); return appDomain.GetAssemblies().SelectMany(o => o.GetTypes().Select(t => new TypeWrapper(null, t))); }
public static System.Type[] GetAllDerivedTypes(this System.AppDomain aAppDomain, System.Type aType) { var result = new List <System.Type>(); var assemblies = aAppDomain.GetAssemblies(); foreach (var assembly in assemblies) { // assemblyがMySql.Dataの時などにGetTypesに失敗したので、一部は無視する // 多分、MySql Connectorをインポートした時にエラーが出なかったDllはプロジェクトに入れなかったからかな? try { var types = assembly.GetTypes(); foreach (var type in types) { if (type.IsSubclassOf(aType)) { result.Add(type); } } } catch (Exception e) { Debug.WriteLine($"{assembly.FullName} failed GetTypes()"); } } return(result.ToArray()); }
public void Add(AppDomain appDomain) { foreach (Assembly assembly in appDomain.GetAssemblies()) { Add(assembly); } }
// Private Methods private static void Print(AppDomain defaultAppDomain) { Assembly[] loadedAssemblies = defaultAppDomain.GetAssemblies(); Console.WriteLine("Here are the assemblies loaded in {0}\n", defaultAppDomain.FriendlyName); foreach (Assembly a in loadedAssemblies) PrintAssemblyName(a.GetName()); }
public static void RegisterAllAssemblies(IExecutionContext context, AppDomain domain) { foreach(Assembly assembly in domain.GetAssemblies()) { context.RegisterAssembly(assembly); } }
/// <summary> /// Discovers the services. /// </summary> public static void DiscoverServices(string prefix, AppDomain domain, bool cors) { IEnumerable<Assembly> possibleAssemblies = domain.GetAssemblies(); IList<Type> possibleTypes = new List<Type>(); foreach (Assembly assembly in possibleAssemblies) { if (!assembly.FullName.StartsWith("System")) { foreach (Type type in assembly.GetTypes()) { if (IsValidService(type)) { string name = string.IsNullOrEmpty(prefix) ? type.Name.ToLower() : prefix + "/" + type.Name.ToLower(); if (cors) { RouteTable.Routes.Add(new ServiceRoute(name, new CorsEnabledServiceHostFactory(), type)); } else { RouteTable.Routes.Add(new ServiceRoute(name, new WebServiceHostFactory(), type)); } } } } } }
public Assembly GetAssembly(AppDomain _domain, string _name) { foreach (Assembly _asm in _domain.GetAssemblies ()) { if (_asm.GetName ().Name == _name) return _asm; } return null; }
public static List<IMessageHandler> CreateMessageHandlersFromDomain(AppDomain appDomain) { //http://stackoverflow.com/questions/5120647/instantiate-all-classes-implementing-a-specific-interface var interfaceType = typeof(IMessageHandler); return appDomain.GetAssemblies() .SelectMany(x => x.GetTypes()) .Where(x => interfaceType.IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract) .Select(x => Activator.CreateInstance(x) as IMessageHandler).ToList(); }
private static void PrintAssemblies(AppDomain appDomain) { Console.WriteLine(); Console.WriteLine("{0} assemblies:", appDomain.FriendlyName); foreach (var assembly in appDomain.GetAssemblies()) { Console.WriteLine(" {0}", assembly.FullName); } }
private static IEnumerable<IPartRegistry<IContractService>> GetPublicPartRegistryInstancesInAppDomain(AppDomain domain) { var registryInstancesLocatedInDomain = domain .GetAssemblies() .SelectMany(x => PartRegistryTypeFilter.Filter(x.GetTypes())) .Select(CreatePartRegistryInstance); return registryInstancesLocatedInDomain; }
// Extensions to check for class derived from proto IMessage<> generics public static IEnumerable <Type> GetAllProtoObjectTypes(this System.AppDomain aAppDomain) { // sort by name to ensure similar order across execution environments return(aAppDomain.GetAssemblies() .Where(aa => !(aa.FullName.Contains("UnityEditor") || aa.FullName.Contains("Google.Protobuf") || aa.FullName.Contains("UnityEngine"))) .SelectMany(aa => aa.GetProtoTypesFromAssembly()) .OrderBy(x => x.Name)); }
private void ReadAppDomain( AppDomain appDomain ) { Assembly[] loadedAssemblies = appDomain.GetAssemblies(); Console.WriteLine( "*************** Assemblies in {0} ***************", appDomain.FriendlyName ); foreach (Assembly assembly in loadedAssemblies) { Console.WriteLine( "->Name: {0}", assembly.GetName().Name ); Console.WriteLine( "->Version: {0}\n", assembly.GetName().Version ); } }
private static void ListAllAssembilesInAppDomain(AppDomain appDomain) { var loadedAssemblies = from asm in appDomain.GetAssemblies() orderby asm.GetName().Name select asm; Console.WriteLine("************************* Assembiles loaded in {0} **", appDomain.FriendlyName); foreach (Assembly a in loadedAssemblies) { Console.WriteLine("-> Name: {0}", a.GetName().Name); Console.WriteLine("-> Version: {0}\n", a.GetName().Version); } }
/// <summary> /// 注册应用域(指定域)。 /// </summary> /// <param name="appDomain">应用域对象。</param> public void RegisterAppDomain(System.AppDomain appDomain) { if (appDomain == null) { return; } foreach (System.Reflection.Assembly item in appDomain.GetAssemblies()) { RegisterAssembly(item); } }
public void RegsiterTypesInDomain(System.AppDomain domain = null) { if (domain == null) { domain = AppDomain.CurrentDomain; } foreach (System.Reflection.Assembly asm in domain.GetAssemblies()) { RegsiterTypesInAssambly(asm); } }
System.Reflection.Assembly myAppDomain_AssemblyResolve(object sender, ResolveEventArgs args) { System.AppDomain domain = (System.AppDomain)sender; foreach (System.Reflection.Assembly asm in domain.GetAssemblies()) { if (asm.FullName == args.Name) { return(asm); } } return(null); }
private static void FindAndPrintAssembly(AppDomain appDomain, string assemblyName) { var anAssembly = appDomain.GetAssemblies().Where(assembly => assembly.GetName().Name.Equals(assemblyName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (anAssembly == null) { Console.WriteLine("Did not find Assembly {0} in {1})", assemblyName, appDomain.FriendlyName); } else { Console.WriteLine("Found Assembly --> {0} (version:{1}) in {2}", anAssembly.GetName().Name, anAssembly.GetName().Version, appDomain.FriendlyName); } }
static void ListAllAssembliesInAppDomain(AppDomain ad) { var loadedAssemblies = from a in ad.GetAssemblies() orderby a.GetName().Name select a; Console.WriteLine("***** Here are the assemblies loaded in {0} *****\n", ad.FriendlyName); foreach (Assembly assembly in loadedAssemblies) { Console.WriteLine("-> Name: {0}", assembly.GetName().Name); Console.WriteLine("-> Version: {0}", assembly.GetName().Version); } }
public static void Configure( AppDomain appDomain, IContainer container, IConventionConfigurator[] conventionConfigurators) { lock (Configured) { if (Configured.ContainsKey(appDomain) && Configured[appDomain].Contains(container)) { throw new InvalidOperationException( "Application from this domain has been configured for this container already. " + "AppllicationConfigurator.Configure() must be called once per AppDomain per Container."); } if (Configured.ContainsKey(appDomain)) { Configured[appDomain].Add(container); } else { Configured.Add(appDomain, new HashSet<IContainer> {container}); } } var assemblies = appDomain.GetAssemblies(); foreach (var assembly in assemblies) { var assemblyTypes = assembly.GetTypes(); Type assemblyConfiguratorType; try { assemblyConfiguratorType = assemblyTypes.SingleOrDefault(x => x.IsAssignableFrom(typeof (IAssemblyConfigurator))); } catch (Exception exception) { var s = string.Join(string.Format(",{0}", Environment.NewLine), assemblyTypes.Where(x => x.IsAssignableFrom(typeof (IAssemblyConfigurator))) .Select(x => x.FullName)); throw new Exception(string.Format("Found more than one assembly configurators in assembly '{0}'. " + "There must be only one configurator in assembly. " + "Configurator types found:{1}{2}", assembly.FullName, Environment.NewLine, s), exception); } if (assemblyConfiguratorType != null) { var assemblyConfigurator = (IAssemblyConfigurator)Activator.CreateInstance(assemblyConfiguratorType); assemblyConfigurator.Configure(container, assemblyTypes); } assemblyTypes.ForEach(assemlyType => conventionConfigurators.ForEach(x => x.Configure(container, assemlyType))); } }
public static Assembly CheckIfAssemblyLoaded(string fullAssemblyName, AppDomain domain) { var assemblies = domain.GetAssemblies(); foreach (var assembly in assemblies) { var assemblyName = new AssemblyName(assembly.FullName); if (assemblyName.Name == fullAssemblyName) { return assembly; } } return null; }
static StackObject *GetAssemblies_1(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.AppDomain instance_of_this_method = (System.AppDomain) typeof(System.AppDomain).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.GetAssemblies(); return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method)); }
/// <summary> /// 从指定应用程序域中根据类型名称查找该类型所属的程序集 /// </summary> /// <param name="appDomain"></param> /// <param name="typeName"></param> /// <returns></returns> public static Assembly FindAssemblyFromAppDomain(AppDomain appDomain, string typeName) { Assembly[] assemblies = appDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { Type[] types = assembly.GetTypes(); foreach (Type type in types) { if (type.FullName == typeName) return assembly; } } return null; }
private void GetAllPlugins(AppDomain domain) { var pluginType = typeof(Layer); var types = domain.GetAssemblies() .SelectMany(a => a.GetTypes()) .Where(t => t.GetInterface(pluginType.Name) != null); var ctors = types.Select(t => t.GetConstructor(new Type[] { })) .Where(c => c != null); _plugins.Clear(); _plugins.AddRange(ctors.Select(c => c.Invoke(null)) .Cast<Layer>()); }
static void ListAllAssembliesInAppDomain(AppDomain ad) { // Now get all loaded assemblies in the default app domain. var loadedAssemblies = from a in ad.GetAssemblies() orderby a.GetName().Name select a; Console.WriteLine("***** Here are the assemblies loaded in {0} *****\n", ad.FriendlyName); foreach (var a in loadedAssemblies) { Console.WriteLine("-> Name: {0}", a.GetName().Name); Console.WriteLine("-> Version: {0}\n", a.GetName().Version); } }
private static Type GetEntityType(string FullName) { System.AppDomain _Domain = System.AppDomain.CurrentDomain; Assembly[] _LoadAssembly; _LoadAssembly = _Domain.GetAssemblies(); System.Type tt2 = null; foreach (Assembly item in _LoadAssembly) { tt2 = item.GetType(FullName); if (tt2 != null) { break; } } return(tt2); }
public static RemoteLoader CreateInstance(AppDomain remoteDomain, string csUnitRoot) { try { remoteDomain.SetData("csUnitRoot", csUnitRoot); var remoteLoader = (RemoteLoader) remoteDomain.CreateInstanceFromAndUnwrap( Path.Combine(csUnitRoot, "csUnit.Core.dll"), typeof(RemoteLoader).FullName); return remoteLoader; } catch (Exception ex) { Debug.WriteLine(string.Format("## Listing assemblies in domain '{0}'##", remoteDomain.FriendlyName)); foreach (var assembly in remoteDomain.GetAssemblies()) { Debug.WriteLine(assembly.FullName); } Debug.WriteLine("## end of list ##"); Debug.WriteLine("Could not instantiate remote loader. " + ex); return null; } }
/// From: /// https://answers.unity.com/questions/983125/c-using-reflection-to-automate-finding-classes.html /// /// Sample usage: /// Type t = System.AppDomain.CurrentDomain.GetTypeByName("typeName"); public static System.Type GetTypeByName(this System.AppDomain appDomain, string typeName) { System.Type result = null; var assemblies = appDomain.GetAssemblies(); foreach (var assembly in assemblies) { var types = assembly.GetTypes(); foreach (var type in types) { if (type.Name == typeName) { result = type; } } } return(result); }
public List <System.Type> GetAllDerivedTypes(System.AppDomain appDomain, System.Type baseType) { var result = new List <System.Type> (); var assemblies = appDomain.GetAssemblies(); for (int i = 0; i < assemblies.Length; i++) { var types = assemblies[i].GetTypes(); for (int j = 0; j < types.Length; j++) { if (types[j].IsSubclassOf(baseType)) { result.Add(types[j]); } } } return(result); }
public static System.Type[] GetAllDerivedTypes(this System.AppDomain aAppDomain, System.Type aType) { var result = new List <System.Type>(); var assemblies = aAppDomain.GetAssemblies(); foreach (var assembly in assemblies) { var types = assembly.GetTypes(); foreach (var type in types) { if (type.IsSubclassOf(aType)) { result.Add(type); } } } return(result.ToArray()); }
static void ListAllAssembliesInAppDomain(AppDomain defaultAD) { Console.WriteLine("***** Here are the assemblies loaded in {0} *****\n",defaultAD.FriendlyName); var laLinq = from llq in defaultAD.GetAssemblies() orderby llq.GetName().Name select string.Format("->Name: {0},Version: {0}\n", llq.GetName().Name, llq.GetName().Version); foreach (var lq in laLinq) { Console.WriteLine(lq); //} //Assembly[] la = defaultAD.GetAssemblies(); //foreach (Assembly ab in la) //{ // Console.WriteLine("->Name: {0}", ab.GetName().Name); // Console.WriteLine("->Version: {0}", ab.GetName().Version); //} } }
public static System.Type[] GetTypesWithInterface(this System.AppDomain aAppDomain, System.Type aInterfaceType) { List <System.Type> result = new List <System.Type>(); System.Reflection.Assembly[] assemblies = aAppDomain.GetAssemblies(); foreach (var assembly in assemblies) { var types = assembly.GetTypes(); foreach (var type in types) { if (aInterfaceType.IsAssignableFrom(type)) { result.Add(type); } } } return(result.ToArray()); }
//可以使用工具类 public static T[] GetAllImplementTypes <T> (System.AppDomain aAppDomain) where T : class { var result = new List <T>(); var assemblies = aAppDomain.GetAssemblies(); foreach (var assembly in assemblies) { var types = assembly.GetTypes(); foreach (var type in types) { if (typeof(T).IsAssignableFrom(type)) { if (!type.IsAbstract) { var tar = assembly.CreateInstance(type.FullName) as T; result.Add(tar); } } } } return(result.ToArray()); }
private static void AssembliesToString(StringBuilder builder, AppDomain domain) { foreach (Assembly assembly in domain.GetAssemblies()) { AssemblyName name = assembly.GetName(); builder.Append(name.Name); builder.Append(" (Version="); builder.Append(name.Version); builder.AppendLine(")"); try { Module module = assembly.GetModule(Path.GetFileName(assembly.Location)); if (module != null) { PortableExecutableKinds kinds; ImageFileMachine machine; builder.Append(" PE: "); FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(module.FullyQualifiedName); if (!string.IsNullOrEmpty(versionInfo.FileVersion)) { builder.Append("Version="); builder.Append(versionInfo.FileVersion); builder.Append(", "); } module.GetPEKind(out kinds, out machine); builder.Append("Kind="); builder.Append(kinds); builder.AppendLine(); } } catch (Exception exception) { builder.Append(exception.Message); } builder.Append(" CodeBase: "); builder.AppendLine(name.EscapedCodeBase); } builder.Length -= Environment.NewLine.Length; }
public static System.Type[] GetAllDerivedObjects(System.Type targetType) { System.AppDomain aAppDomain = System.AppDomain.CurrentDomain; List <System.Type> result = new List <System.Type>(); var assemblies = aAppDomain.GetAssemblies(); foreach (var assembly in assemblies) { var types = assembly.GetTypes(); foreach (var type in types) { if (type.IsSubclassOf(targetType)) { result.Add(type); } } } return(result.ToArray()); }
/// <summary> /// Helper method that returns resource size data for the current appdomain including a calulation of processor utilisation since the last snapshot. /// Warning: If called from an app domain that is restricted, a security exception will be thrown due to the method existing in a separate assembly. /// It is recommended that this method is copied into the assembly where the app domain is created. /// </summary> /// <param name="lastSnapshot">When provided, enables calculation of delta processor usage</param> /// <returns></returns> public static List<ResourceSnapshot> GetAppDomainResourceSnapshots(AppDomain appDomain, List<ResourceSnapshot> lastSnapshot = null) { //discover how much time has elapsed since we last acquired processor time ResourceSnapshot processorTimeSnapshot = null; if (lastSnapshot != null) { processorTimeSnapshot = lastSnapshot.FirstOrDefault(f => f.ResourceName == WellKnownResourceNames.AppDomainTotalProcessorTime); } double processorMsTotal = appDomain.MonitoringTotalProcessorTime.TotalMilliseconds; double timeMsElapsed = 0; double processorMsElapsed = processorMsTotal; double utilization = 0; var snapshots = new List<ResourceSnapshot>() { new ResourceSnapshot(WellKnownResourceNames.AppDomainTotalMemoryAllocation, appDomain.MonitoringSurvivedMemorySize), new ResourceSnapshot(WellKnownResourceNames.AppDomainTotalProcessorTime, processorMsTotal), new ResourceSnapshot(WellKnownResourceNames.AppDomainAssemblyCount, appDomain.GetAssemblies().Count()), }; if (processorTimeSnapshot != null) { timeMsElapsed = DateTime.UtcNow.Subtract(processorTimeSnapshot.DateAcquired).TotalMilliseconds; processorMsElapsed = processorMsTotal - processorTimeSnapshot.Value; utilization = (processorMsElapsed / Environment.ProcessorCount) / timeMsElapsed; //shouldn't happen if (utilization > 1) utilization = 1; snapshots.Add(new ResourceSnapshot(WellKnownResourceNames.AppDomainIntervalProcessorTimeInterval, timeMsElapsed)); snapshots.Add(new ResourceSnapshot(WellKnownResourceNames.AppDomainIntervalProcessorTime, processorMsElapsed)); snapshots.Add(new ResourceSnapshot(WellKnownResourceNames.AppDomainIntervalUtilization, utilization)); } return snapshots; }
private void GetAssemblies(AppDomain appDomain) { //Provide the current application domain evidence for the assembly. System.Security.Policy.Evidence asEvidence = appDomain.Evidence; //Load the assembly from the application directory using a simple name. //Create an assembly called CustomLibrary to run this sample. //currentDomain.Load("CustomLibrary", asEvidence); //Make an array for the list of assemblies. Assembly[] assems = appDomain.GetAssemblies(); //List the assemblies in the current application domain. Log.Write(assems, this, "GetAssemblies", Log.LogType.DEBUG); }
void PrintLoadedAssemblies(AppDomain domain) { foreach (Assembly a in domain.GetAssemblies()) { Logger.Log.Info("Assembly loaded: " + a.FullName); } }
private static Assembly LoadAssambly(AppDomain domain, string assambly) { Assembly assemble; try { if (Logger.IsTraceEnabled && Log.IsDebugEnabled) { Log.DebugFormat("loadAssambly('{0}') called...", assambly); } string assambly1 = assambly; if(assambly1.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) || assambly1.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) { assambly1 = assambly1.Substring(0, assambly1.Length - 4); } var assembles = domain.GetAssemblies(); foreach (var assembleLoaded in assembles) { var an = assembleLoaded.GetName(); if (String.Compare(an.Name, assambly1, StringComparison.OrdinalIgnoreCase) == 0) { return assembleLoaded; } } // Load the requested assembly from file if (string.IsNullOrEmpty(domain.SetupInformation.CachePath)) { /*if (logger.IsDebugEnabled) { logger.DebugFormat(@"App ApplicationBase '{0}', CachePath is {1}, PrivateBinPath is {2} ShadowCopyDirectories: {3} ", domain.SetupInformation.ApplicationBase, domain.SetupInformation.CachePath, domain.SetupInformation.PrivateBinPath, domain.SetupInformation.ShadowCopyDirectories); }*/ } if(File.Exists(assambly)) { //assambly = IOUtil.GetFullPath(assambly); //assemble = Assembly.LoadFile(assambly); assemble = Assembly.LoadFrom(assambly); //byte[] buf = IOUtil.binReadFile(assambly); //assemble = domain.Load(buf); } else { if (!Path.IsPathRooted(assambly)) { if (AssemblyPathes.Select(t => t + Path.DirectorySeparatorChar + assambly).Any(File.Exists)) { var buf = IOUtil.BinReadFile(assambly); assemble = domain.Load(buf); return assemble; } } assemble = domain.Load(assambly); } } catch (FileNotFoundException e) { if (Logger.IsTraceEnabled) Log.ErrorFormat("Could not load Assembly '{0}', error: {1}", assambly, e.Message); throw; } return assemble; }
private static void AppDomainInfo(AppDomain domain, TextWriter output) { if (domain == null) return; output.WriteLine("</PRE><H3>AppDomain info</H3><PRE>"); output.WriteLine("FriendlyName = {0}", domain.FriendlyName); output.WriteLine("ApplicationBase = {0}", domain.SetupInformation.ApplicationBase); output.WriteLine("ConfigurationFile = {0}", domain.SetupInformation.ConfigurationFile); output.WriteLine("DynamicBase = {0}", domain.SetupInformation.DynamicBase); output.WriteLine("PrivateBinPath = {0}", domain.SetupInformation.PrivateBinPath); output.WriteLine("CachePath = {0}", domain.SetupInformation.CachePath); output.WriteLine("ShadowCopyDirectories = {0}", domain.SetupInformation.ShadowCopyDirectories); output.WriteLine("ShadowCopyFiles = {0}", domain.SetupInformation.ShadowCopyFiles); if (domain == AppDomain.CurrentDomain) { foreach (Assembly assembly in domain.GetAssemblies()) output.WriteLine(" Assembly: {0}", assembly.FullName); } else { foreach (string name in Remoter.CreateRemoteInstance(domain).GetLoadedAssemblies()) output.WriteLine(" Assembly: {0}", name); } }
/// <summary> /// Gets the loaded assemblies by using the right method. For Windows applications, it uses /// <c>AppDomain.GetAssemblies()</c>. For Silverlight, it uses the assemblies /// from the current application. /// </summary> /// <param name="appDomain">The app domain to search in.</param> /// <returns><see cref="List{Assembly}" /> of all loaded assemblies.</returns> public static List<Assembly> GetLoadedAssemblies(AppDomain appDomain) { var assemblies = new List<Assembly>(); #if SL4 assemblies.AddRange(_frameworkAssemblies); #else assemblies.AddRange(appDomain.GetAssemblies()); #endif #if SILVERLIGHT try { if (Deployment.Current != null) { foreach (AssemblyPart assemblyPart in Deployment.Current.Parts) { #if WINDOWS_PHONE try { // It's not much, but it's the best we could do for WP7 assemblies.Add(Assembly.Load(assemblyPart.Source.Replace(".dll", string.Empty))); } catch (Exception) { // Continue, let's hope this assembly is not required } #else var sri = Application.GetResourceStream(new Uri(assemblyPart.Source, UriKind.Relative)); var assembly = assemblyPart.Load(sri.Stream); if (assembly != null) { assemblies.Add(assembly); } #endif } } } catch (Exception ex) { Log.Error(ex, "Failed to load Deployment.Current.Parts"); } #if SL4 || SL5 // Add the loaded xap cache assemblies.AddRange(_externalAssemblies); #endif #endif // Make sure to prevent duplicates assemblies = assemblies.Distinct().ToList(); // Map all assemblies foreach (var assembly in assemblies) { RegisterAssemblyWithVersionInfo(assembly); } return assemblies; }
public static void PrintAllAssembliesInAppDomain(AppDomain ad) { Assembly[] loadedAssemblies = ad.GetAssemblies(); Console.WriteLine(@"***** Here are the assemblies loaded in {0} *****\n", ad.FriendlyName); foreach (Assembly a in loadedAssemblies) { Console.WriteLine(@"-> Name: {0}", a.GetName().Name); Console.WriteLine(@"-> Version: {0}", a.GetName().Version); } }
public static Assembly[] GetAppAssemblies(this AppDomain @this) { return(@this.GetAssemblies() .Where(x => x.FullName.StartsWith(AssemblieName)) .ToArray()); }
public static IEnumerable <Type> GetAppTypes(this AppDomain @this) { return(@this.GetAssemblies() .Where(x => x.FullName.StartsWith(AssemblieName)) .SelectMany(x => x.GetTypes())); }
public static Boolean TryGetLoadedAssembly(AppDomain Domain, String AssemblyPath, out Assembly LoadedAssembly) { Assembly[] assemblies = Domain.GetAssemblies(); foreach (Assembly assembly in assemblies) { if (assembly.Location.ToUpper() == AssemblyPath) { LoadedAssembly = assembly; return true; } } LoadedAssembly = null; return false; }