mercredi 1 septembre 2021

c# - Get a list of Type objects from another DLL

I have a web app that uses 2 custom DLLs. One is a mini-ORM I made on top of Dapper and the other is a class library containing all my model classes. My ORM has a class that runs at startup, scans a provided package for types and builds a field registry for the ORM to use. This class used to be in the same class library as the models and it worked perfectly since it was able to find the classes within its own class library. Ever since I moved it to the ORM library, it (predictably) stopped working because of this line :

var types = Assembly.GetAssembly()
            .GetTypes()
            .Where(t => t.IsClass)
            .Where(t => t.Namespace != null)
            .Where(t => t.Namespace.StartsWith(packageName));

I tried replacing GetAssembly() by GetEntryAssembly() thinking the calling web app would encapsulate all the model classes it found in the models library but it looks like I was wrong.

My question in a nutshell is : Is there a way to access types contained in a DLL from a different DLL through a parent web app that references both?





Aucun commentaire:

Enregistrer un commentaire