是否有可能使用Assembly.ReflectionOnlyLoad与出版商政策/集版本?有可能、出版商、版本、政策

2023-09-03 22:29:17 作者:再玩lol我就拆你R键

我们正在使我们的产品与未安装的是我们,因为许可产品的一部分的第三方组件(库)集成。目前,我们只希望,如果这些组件安装在客户端机器上加载相关的第三方组件的功能。

We are allowing to integrate our product with third party components (libraries) which are not installed as part of our product because of licensing. At the moment we want to load features related to third party components only if these components are installed on the client's machine.

我用 Assembly.ReflectionOnlyLoad 与提供的第三方组件的全名相关功能的应用程序加载之前验证安装第三方组件。这适用于以下情况:

I'm using Assembly.ReflectionOnlyLoad with providing full names of third party assemblies to validate installation of third party components before the application loads related features. This works for following scenarios:

库完全版本安装到GAC 在库的精确版本复制到应用程序目录/探测路径

现在我需要修改的解决方案,以支持发行政策(重定向程序集绑定到新版本)。我刚刚测试了我的code,它看起来像 ReflectionOnlyLoad 忽略部署到GAC发行政策,因此,即使第三方组件的安装是否正确我的机制将不会加载预期功能(新版本与装配重定向)。

Now I need to modify the solution to support publisher policies (redirecting assembly binding to new version). I just tested my code and it looks like ReflectionOnlyLoad ignores publisher policy deployed to GAC so my mechanism will not load expected features even third party assemblies are correctly installed (new version with assembly redirection).

如果我删除了我的验证(=功能将在每次加载)的应用程序将正确加载的第三方组件的新版本,因此出版商策略工作正常,因为功能与依赖于旧版本仍然编译。

If I remove my validation (= features will be loaded every time) the application will correctly load new version of third party assemblies so publisher policy works correctly because features are still compiled with dependency to old version.

如何使用版本控制和装配重定向验证时存在两种GAC的组装和探测路径?

How to validate existence of the assembly in both GAC and probing paths when using versioning and assembly redirection?

推荐答案

您不能只用 ReflectionOnlyLoad

ReflectionOnlyLoad 的全部目的和朋友是能够检查程序集元数据不考虑政策和版本。

The entire purpose of ReflectionOnlyLoad and friends is to be able to inspect the assembly metadata without regard to policy and versioning.

李俊峰张解释了这个在他考试的 ReflectionOnlyLoad 方法的。

我怀疑,如果你想申请的政策,加载,你需要加载的程序集在一个单独的AppDomain,做推理过来的。这种方法的好处是,你可以卸载的AppDomain 您使用反射和验证。不足之处是它引入了显著的复杂性。我没有看到太多的选择,但是。

I suspect that if you want to apply policy to loading, you'll need to load the assemblies in a separate AppDomain and do reasoning about them there. The benefit of this approach will be that you will be able to unload the AppDomain you use for reflection and verification. The downside is it introduces significant complexity. I don't see much alternative, however.

一旦你有一个单独的的AppDomain ,你需要有一定的 MarshalByRefObject的类,允许你做验证在远程的AppDomain 从主之一。这个类可以加载到远程的AppDomain ,也做任何的Assembly.Load 通话,跟踪的结果。当它完成之后,将返回某种报告,在主的AppDomain 的来电。最后,你可以卸载远程的AppDomain 。您加载的类型不会有主的AppDomain已加载

Once you have a separate AppDomain, you will need to have some MarshalByRefObject class to allow you to do verification in the remote AppDomain from your main one. That class can be loaded into the remote AppDomain and also do any Assembly.Load calls, keeping track of the results. When it is done, you return some kind of report to the caller in the main AppDomain. Finally, you can unload the remote AppDomain. The types you loaded there will not have been loaded in the main AppDomain.