开发者

reference GAC assembly with fallback version

开发者 https://www.devze.com 2023-03-04 17:38 出处:网络
My project references version 2.0.0.0 of an assembly in the GAC.If version 2.0.0.0 is not available, I\'d like to redirect/change the reference to version number 1.0.0.0.

My project references version 2.0.0.0 of an assembly in the GAC. If version 2.0.0.0 is not available, I'd like to redirect/change the reference to version number 1.0.0.0.

Some research came up with the following posts, but they don't seem to be directly related to my scenario:

How to provide a fallback assembly instead of the one that can't be loaded?

How to reference to multiple version assembly

I believe that strongly-named assemblies required a specific version number, so I don't think the reference itself can use wildcard (*)? What is the simpliest way to s开发者_开发技巧olve my scenario?


The solution is to use a bindingRedirect. Apparently it works if the oldVersion is higher than the newVersion, as in my scenario. http://www.infosysblogs.com/microsoft/2007/04/loading_multiple_versions_of_s.html

No code changes - simple config addition.


If you need to dynamically load arbitrary assemblies and classes, you can use Assembly.Load (or one of its variations) and Assembly.CreateInstance().

The reason you need to do it this way is it allows late binding. Referencing an assembly in the GAC is an early binding scenario, and cannot be changed as such at runtime.

0

精彩评论

暂无评论...
验证码 换一张
取 消