How to change dll from Reference with running application?

Asked

Viewed 82 times

0

I have a project where I need to use a reference with different versions in a single execution, example:

Switch System.Drawing version 2.0.0 to System.Drawing version 1.0.0

It’s possible to do that?

  • Why is that necessary? Describe your problem better, as there may be other ways to solve it that may have nothing to do with the System.Drawing

  • 1

    I was curious to know why you want this, for me it doesn’t make sense

  • @Exact Rovannlinhalis... because you can even make copying, renaming and using alias... But I can’t see any sense in it.

  • @Leandroangelo I don’t think so... but I’ll wait for the reason of the thing

  • I’m dealing with system integration, where older versions of the system uses dll with an older version and when the program is doing calculations on newer systems, it needs to change the reference of this old dll to a newer version. Basically I can’t use this recent dll on an old system, so I have to change it. And I need to do this on the same run. Because I will make calculations on different version systems with the same dll (with different versions).

  • It is possible to load a dll dynamically, but cannot be referenced. If you have already added this reference to your project, it cannot be changed and the program will use this reference. In your case you will not be able to reference this dll and then load the ones you need dynamically using Assembly.Load(path). Then you can use dll methods using Reflection.

Show 1 more comment

1 answer

0

It is possible through a dynamic Assembly invocation:

// caminho da DLL antiga
var assembly = Assembly.LoadFile("caminho");

// tipo da classe desejada
dynamic instancia = assembly.CreateInstance("tipo");

// chamar o método que está procurando ou fazer o que precisar com a variável
instancia.MetodoDesejado();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.