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.
Ahh, ILMerge - that extra info in your question really helps with your problem. While I wouldn't ever expect the .net compiler to fail in this way I would expect to occasionally see this sort of thing with ILMerge (given what it's doing).
My guess is that two of your assemblies are using the same optimisation 'trick', and once merged you get the conflict.
Have you raised the bug with Microsoft?
A workaround in the meantime is to recompile the assemblies from source as a single assembly, saving the need for ILMerge. As the csproj files are just XML lists they're basically easy to merge, and you could automate that as an extra MSBuild step.