I'm trying to search all types that belong to a spesific to all assembly referenced by my project
What I have done , load all assemblies in my project by this :
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();
var loadedPaths = loadedAssemblies.Select(a => a.Location).ToArray();
var referencedPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll");
var toLoad = referencedPaths.Where(r => !loadedPaths.Contains(r, StringComparer.InvariantCultureIgnoreCase)).ToList();
toLoad.ForEach(path => loadedAssemblies.Add(AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(path))));
And then search for specific types
const string @namespace = "name space to search"
var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(t => t.GetTypes())
.Where(t => t.IsClass && t.Namespace == @namespace );
now when I try to iterate over the types , I get a loader exception "Could not load file or assembly 'System.Windows"
and system.windows is not an assembly refrenced by my project
Aucun commentaire:
Enregistrer un commentaire