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?

- 84,773
- 49
- 224
- 367

- 125
- 1
- 5
-
What are you actually trying to achieve by comparing same dlls? Can u not use tools like telerik Just Decompile or IlSpy if you just wanna see what's inside the assemblies? – nabeelfarid Jul 11 '11 at 10:16
-
I have an assignment to create an application that will compare two different versions of a dll. Hence I need to compare the same dlls (of different version) and find out the changes. – user386527 Jul 11 '11 at 10:22
-
2Perhaps something mono cecil based? – CodesInChaos Jul 11 '11 at 10:40
3 Answers
Use the ReflectionOnlyLoad ot ReflectionOnlyLoadFrom methods
You will also need to handle the ReflectionOnlyAssemblyResolve to tell the framework where to find the dependencies.

- 45,695
- 27
- 126
- 169
You can catch the ReflectionTypeLoadException
in order to see the list of types which were loaded correctly. See the following links for some more detail on this:
If you know where the missing assemblies can be found you can also handle the AppDomain.AssemblyResolve
event in order to "help out" with locating and loading the required dependencies.
If you just want to compare two assemblies, you certainly doesn't need to load them. I would suggest a more static approach, based on Mono.Cecil.
It will allow you to compare modules, types, methods -- even at the instruction level, in a simple manner.
Getting started documentation can be found here :

- 12,833
- 7
- 57
- 77