Bug 19509

Summary: mcs reorders methods and properties in interfaces
Product: [Mono] Compilers Reporter: eb1
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+mono
Priority: ---    
Version: 3.2.x   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Disassembler output from assembly compiled with Mono 3.4.0
Disassembler output from assembly compiled with Mono 2.10.9
Sample interface code

Description eb1 2014-05-03 17:00:20 UTC
The C# compiler changes the order of methods and properties and puts the properties first. This is very bad when the interface is for an unmanaged class as is the case with COM interop. The program will crash because the wrong method gets called.

This is a regression introduced sometime after 2.10.9.

To reproduce:
Compile the following interface:

interface Iface
{
	int A { get; }
	void B();
	void C(int a, string b);
	string D { get; }
}

compile with: mcs -out:MonoBug.dll Iface.cs

then disassemble with: monodis --output MonoBug.asm MonoBug.dll

MonoBug.asm shows that the order of methods is A, D, B, C when compiled with Mono 3.4.0, whereas it is A, B, C, D when compiled with Mono 2.10.9 and with .NET.

Attached is the interface as well as the disassembler output from the assembly compiled with Mono 3.4.0 and Mono 2.10.9
Comment 1 eb1 2014-05-03 17:01:15 UTC
Created attachment 6723 [details]
Disassembler output from assembly compiled with Mono 3.4.0
Comment 2 eb1 2014-05-03 17:01:40 UTC
Created attachment 6724 [details]
Disassembler output from assembly compiled with Mono 2.10.9
Comment 3 eb1 2014-05-03 17:02:16 UTC
Created attachment 6725 [details]
Sample interface code
Comment 4 eb1 2014-05-03 17:22:24 UTC
Same thing happens when generating code from CodeDOM.
Comment 5 eb1 2014-05-05 11:08:21 UTC
When generating code this behaviour is expected. It can be modified by setting CodeGeneratorOptions.VerbatimOrder property.
Comment 6 Marek Safar 2014-05-05 11:55:48 UTC
Fixed in master
Comment 7 eb1 2014-05-05 12:06:51 UTC
Thanks for the quick fix!