You can't do that, if you want to use a dll that you select at runtime, you need to start by NOT referencing it directly in your project (that can't be changed at runtime) then manually loading it in your appdomain using Assembly.Load and reflect upon it to use it's types (as you don't know the types at compile time as it's not referenced, so you have to program it against types you query).
So if you already programmed against the referenced dll, you did it wrong, as the whole way of using the code Inside it is diferent if you need it to be dynamic.
For example if you have a type "mytype" with a method "mymethod" in a dll named "mydll.dll" if you reference it using it is as simple as doing
new mytype().mymethod();
If you're not referencing the dll but resolving it dynamically it would look like
var asm = Assembly.Load("mydll.dll");
var type = asm.DefinedTypes.Single(t=>t.Name == "mytype");
var instance = Activator.CreateInstance(type);
var methodinfo = type.GetMethod("mymethod");
methodinfo.Invoke(instance);
Also we need to know what you're trying to achieve, there are ways to make this a bit simpler but it depends on your use case (in a plugin system for example you'd declare an interface for the plugin and share that dll and reference it directly, only loading the plugins dynamically, so you could directly cast instance to that interface and not have to invoke methods dynamically)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…