Loading Assemblies

女生的网名这么多〃 提交于 2019-12-23 22:25:55

问题


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:


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.




回答2:


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



来源:https://stackoverflow.com/questions/1588360/loading-assemblies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!