views:

70

answers:

2
+2  Q: 

Loading Assemblies

Hi guys,

There are plenty of discussing that shows how to load assemblies from BIN and from GAC... my question is more general and I would love to know how assembly loading work.

As for example

in the BIN folder we can have

A.dll
A.dll.config

A.dll.config file can look like:

<?xml version="1.0"?>
<configuration>
  <startup>
    <supportedRuntime version="v2.0.50727"/>
  </startup>
</configuration>

to help us setting the correct assembly reference.

I was wondering how can I create a A.dll that needs B.dll but without specify any version so if would always take the B.dll that is in the BIN Folder.

My question is regarding an update of the SDK and all my code still points to the old SDK version, I wanted to have my assembly look for the top most of all versions of the resource, BIN or GAC and use that one...

How can I say that in Visual Studio? I can only Add Reference to a physical file (version) :-(

+1  A: 

You can use late binding and Reflection. There are many places to read about this, but you can start here.

Randolph Potter
+1  A: 

If I understand correctly, I guess you could use the "plugins" way of doing things through the AppDomain object. Perhaps loading the assembly through the AppDomain, since you can set the path for the loaded assembly, you will be able to easily replace the files, unload the assembly and reload the new one in ShadowCopy. The ShadowCopy allows you to copy the latest file at the same location of the current file assembly. Then, build your mechanism to check for a new file, and if it exists, then unload your assembly and reload the latest. This way, everything will be quite transparent for your program, though it requires a bit more programming from your side. Nevertheless, you will gain in long term development.

Will Marcouiller