jeudi 7 juillet 2016

Can I add a dependency reference programmatically to the calling assembly

When a class library is executing, you have access to a few Assembly methods.

Assembly.GetExecutingAssembly()
Assembly.GetEntryAssembly()
Assembly.GetCallingAssembly()

Each of these has a .GetReferencedAssemblies() method

If I call

Assembly.GetExecutingAssembly().GetReferencedAssemblies()

I get a list of all the dependent libraries for the assembly the current class is within.

However my code has been called by an engine using reflection and it is actually the parent application that needs the dependency to be there.

Assembly.GetCallingAssembly().GetReferencedAssemblies()
Assembly.GetEntryAssembly().GetReferencedAssemblies()

Both give me the list of dependencies I need to add to.

However every method I have tried to programmatically add an assembly, eg Assembly.Load, Assembly.LoadFrom all only add it to the GetExecutingAssembly().GetReferencedAssemblies() list, not the dependencies for the calling or entry assembly.

Is there a way to programmatically add an assembly to the references list of the calling or entry assembly, not the currently executing one?





Aucun commentaire:

Enregistrer un commentaire