C# - 使用反射比较两个 .net dll [英] C# - comparing two .net dlls using reflection

查看:81
本文介绍了C# - 使用反射比较两个 .net dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较位于不同位置的两个相同的 .net dll.因此,我使用 System.Reflection.Assembly.LoadFile(filename) 而不是 System.Reflection.Assembly.LoadFrom(filename) 加载 dll.但是要比较的 .Net dll 引用了其他程序集(与相应的 dll 位于同一文件夹中).使用 LoadFile(filename) 后跟 GetTypes() 加载 dll 会引发 ReflectionTypeLoadException.我应该如何使用反射加载两个相同的 dll 以获得它们的类型 &比较?

I want to compare two identical .net dlls which are located at different locations. Hence, I am loading the dlls using System.Reflection.Assembly.LoadFile(filename) instead of System.Reflection.Assembly.LoadFrom(filename). But the .Net dlls that are to be compared have reference to other assemblies (which are in the same folder as the respective dll). Loading the dll using LoadFile(filename) followed by GetTypes() throws an ReflectionTypeLoadException. How should I load two identical dlls using reflection so as to get their types & compare?

推荐答案

使用 ReflectionOnlyLoadReflectionOnlyLoadFrom 方法

您还需要处理 ReflectionOnlyAssemblyResolve告诉框架在哪里可以找到依赖项.

You will also need to handle the ReflectionOnlyAssemblyResolve to tell the framework where to find the dependencies.

这篇关于C# - 使用反射比较两个 .net dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆