samedi 29 janvier 2022

Invalid class name from reflection .NET 6

I'm trying to get all classes from the namespace:

var commands = Assembly.GetExecutingAssembly().GetTypes()
            .Where(t => String.Equals(t.Namespace, nameSpace, StringComparison.Ordinal))
            .ToList();

I have only one class in this namespace:

enter image description here

But, in commands variable I have 2 classes:
enter image description here

I don't understand why it breaks. I also solved this trouble by adding
!t.FullName!.Contains("<>") in where statement of commands, but I don't think that it's perfect solution.
Can somebody explain me why reflection breaks?





Aucun commentaire:

Enregistrer un commentaire