I have a ASP.NET application running on a remote web server and I just started getting this error:
Method not found: 'Void System.Collections.Generic.ICollection`1..ctor()'.
I disassembled the code in the DLL and it seems like the compiler is incorrectly optimizing the code. (Note that Set is a class that implements a set of unique objects. It inherits from IEnumerable.) This line:
Set<int> set = new Set<int>();
Is compiled into this line:
Set<int> set = (Set<int>) new ICollection<CalendarModule>();
The CalendarModule class is a totally unrelated class!! Has anyone ever noticed .NET incorrectly compiling code like this before?
Update #1: This problem seems to be introduced by Microsoft's ILMerge tool. We are currently investigating how to overcome it.
Update #2: We found two ways to solve this problem so far. We don't quite understand what the underlying problem is, but both of these fix it:
Turn off optimization.
Merge the assemblie with ILMerge on a different machine.
So we are left wondering if the build machine is misconfigured somehow (which is strange considering that we have been using the machine to build releases for over a year now) or if it is some other problem.