Mishaa
Mishaa

Reputation: 97

AppDomain.CurrentDomain.GetAssemblies() In C# WinForm

I need to generate a list of my assemblies for a project. I am using this code :

 Assembly[] lstAssembly = AppDomain.CurrentDomain.GetAssemblies();

which is somehow working but It doesn't show all of my namespaces in solution. I want To know why it doesn't show all the namespace in my solution

My solution and its projects are like this:

> MySolution'TST'              
>|-->BaseWinApp(Project1)           
>|-->ProductWinApp(Project2)          
>|-->SaleWinApp(Project3)         
>|-->TST(Start Up Project)

Upvotes: 1

Views: 1674

Answers (2)

Rahul
Rahul

Reputation: 77896

Did you meant to do something like below which would give you the namespace for that assembly

Assembly.GetExecutingAssembly().GetTypes().Select(t => t.Namespace).ToList();

Upvotes: 0

ilkerkaran
ilkerkaran

Reputation: 4354

It returns just directly referenced libraries by default. You need to load recursively if you want to load all of them.

            var myrootAssembly = Assembly.GetExecutingAssembly();
            var loadedPath = myrootAssembly.Location;
            var rootPath = loadedPath.Substring(0, loadedPath.LastIndexOf('\\') + 1);
            var referencedPaths = Directory.GetFiles(rootPath, "*.dll");
            foreach (var refPath in referencedPaths)
            {
                assemblyList.Add(Assembly.LoadFrom(refPath));
            }

Upvotes: 1

Related Questions