Question

I am comparing to make sure 2 dlls are generated from same source. As I could not use external tools to compare, I just created IL files using IL disassembler and comparing manually.

  • For the below fields in a .IL file , the count is same while comparing.

     //   CLR method headers : 
     //   Num.of method bodies  - 
     //   Num.of fat headers    - 
     //   Num.of tiny headers   - 
    
     // Managed code : 
     //   Ave method size - 
    
  • Order of class names are not same while count and names are same .

Is it safe to assume for the above scenarios that both DLLs are from same source code?

Was it helpful?

Solution 2

There's no way to tell this.

Not only are no two compiled DLL's the same because of the MVID and other properties that differ each time you compile: two assemblies containing the same number of methods doesn't tell anything:

  • The implementation of the methods can differ (e.g. v1's Foo() method contains return true, while v2's Foo() contains return false)
  • Different source code can yield the same IL.

It seems like you have an entirely different problem you want to solve, like educating your team and using continuous integration to share assemblies that are compiled on a build server. If you can explain why you want to make sure two DLLs were compiled from the same source, perhaps some better answers can be given.

OTHER TIPS

You can use ILSpy to decompile both DLLs. Use Save Code... option for both libraries, so you can save it as complete Visual Studio project (csproj). Then simple WinMerge (with recursion) on both directories will show you all differences in the source code.

I've recently successfully used this approach to make sure what version of DLL was used on production machines.

I think you can try the following -

  1. try ILSpy for an open source assembly browser and decompiler and compare the c# code generated.
  2. run test cases against the classes in the assembly and validate if the results are the same.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top