mercredi 14 avril 2021

.NET instantiate dynamically loaded type

Here is my current project structure and the problem it gives:

I have 2 different projects, project A (class library) and project B. Project A contains a class C that has a single constructor with a single parameter of type Microsoft.Extensions.Configuration.IConfiguration. In project B I dynamically load the assembly produced by project A. If I now want to instantiate the class C with a custom built Microsoft.Extensions.Configuration.IConfiguration object, it gives an ArgumentError, because the IConfiguration types are not the same and hence can not be converted to each other. This happens because the IConfigurations types come from the same assembly, but at a different location. (One is in A\bin\release\Microsoft.Extensions.Configuration.dll and the other in B\bin\release\Microsoft.Extensions.Configuration.dll)

Is there a way that I could set up the projects such that I can instantiate class C in project B, without a project reference to project A? (This dynamic assembly loading is a requirement that cannot be changed).

Edit: This is my first every StackOverflow post, so suggestions for posing the question better are welcome!





Aucun commentaire:

Enregistrer un commentaire