Mike A Mike A - 2 months ago 5x
C# Question

How can I search the assemblies for all the classes available in a specific namespace with from a controller using c#?

I need to get all available classes in a giving namespace.

Here is what I have done

In my

method in
I added this line.

var classesList = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.Namespace == "PATH.TO.HAMESPACE").ToList()

Unfortunately, that gave me no records/classes.

However, when I created a new class in the the same namespace i.e.
. with the same code. Then called this class from the controller, the code returns the correct classes list.

How can I run this code from the controller to get all available classes with in


Overkill method, but that could work:

    .SelectMany(a => a.GetTypes())
    .Where(t => t.Namespace == "Namespace");

Or (and), you should try to load explicitly your assembly. With Assembly.Load or Assembly.LoadFrom.

Assembly.Load("your assembly fullname")
    .Where(t => t.Namespace == "Namespace");