mercredi 19 avril 2017

How do I reference an assembly with no public types?

I am writing an application that uses some setup code for establishing a database connection and various context settings. I do not have access to the sources of that setup code.

Among many other things, that setup code uses MEF to instantiate a certain class that implements a public interface. An exception will be thrown if no such class is found.

Unfortunately, the only class C that implements that interface is an internal class in an assembly A. Assembly A contains no public types whatsoever (and whose sources I cannot access, either). However, only assemblies whose contents are used get loaded by the CLR, and, while I could trigger the loading with Assembly.Load, I can only get the referenced assembly name from Assembly.GetReferencedAssemblies if some use of the assembly is actually recognized by the compiler - otherwise, the reference will be optimized away.

At runtime, I do not know the physical location of A, which makes dynamical loading by file name problematic. I might be able to guess it by looking at the location of certain other assemblies, but that seems quite hacky to me.

Furthermore, I cannot implement the interface myself (or rather, it would make no sense to do so), as I do not have the information that must be returned by some of the interface's methods. (In fact, as I do not have any documentation for the interface, I am not even sure what the interface members are supposed to do or return in some cases.)

What options do I have to make sure C is around when the setup code attempts to retrieve the interface implementation?





Aucun commentaire:

Enregistrer un commentaire