Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I had created a C#.NET console application and class library project using VS 2010 and checked-in into the version control repository along with the source code and compiled binaries (dll & exe). My collegue took the latest source code from the version control tool and compiled the source code to generate the binaries. As a part of acceptance test both the binaries are compared using beyond compare. The generated binaries are identical in dimension (size) with the binaries available in the version control repository. When we performed hex compare using beyond compare, then it has been observed that there is a lot differences between the binaries generated by me and my collegue.

To investigate the issue, I extracted the OS header and metadata information using the dumpbin utilty. From that data we observed that difference in the binaries is because of timestamp (quite understandable) and raw data under the .text header section. When we closely monitor the dumpbin of the identical binaries some of the raw data were jumbled across the different memory addresses.

Can anyone help me in understanding the reason for this behaviour?

Thanking in advance.

Regards
Sudheendra
Posted
Updated 28-Oct-14 1:28am
v2
Comments
Mehdi Gholam 28-Oct-14 8:32am    
Why does it matter?
Richard Deeming 28-Oct-14 9:15am    
Eric Lippert explains why compiling the same code twice won't produce an identical binary file:
http://blogs.msdn.com/b/ericlippert/archive/2012/05/31/past-performance-is-no-guarantee-of-future-results.aspx[^]
Maciej Los 28-Oct-14 12:11pm    
Richard, post it as an answer!
Richard Deeming 28-Oct-14 12:21pm    
Done. :)

1 solution


Is compiling the same C# program twice guaranteed to produce the same binary output?

No.

Well, that was an easy blog to write.

Maybe some more background might be useful.

Eric goes on to explain the various reasons why compiling the same source code twice won't produce an identical binary file. In addition to having to generate unique names for various compiler artefacts, the compiler generates and inserts a unique GUID into the meta-data of each module, leading to the conclusion that: "the C# compiler by design never produces the same binary twice".

In fact, your question sounds almost identical to the situation that Eric discusses at the end of his post.
 
Share this answer
 
Comments
Maciej Los 28-Oct-14 12:23pm    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900