Is it possible to use Assembly.ReflectionOnlyLoad together with publisher policies / assembly versioning?

情到浓时终转凉″ 提交于 2019-12-05 17:51:48

You can't by using just ReflectionOnlyLoad.

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

Junfeng Zhang explains this in his examination of the ReflectionOnlyLoad methods.

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.

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.

Patrik

It seems you can call AppDomain.ApplyPolicy to have the policies applied to the assembly name. You can then call ReflectionOnlyLoad() on the returned name.

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