Bug 19509 - mcs reorders methods and properties in interfaces
Summary: mcs reorders methods and properties in interfaces
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: 3.2.x
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-05-03 17:00 UTC by eb1
Modified: 2014-05-05 12:06 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Disassembler output from assembly compiled with Mono 3.4.0 (1.79 KB, application/octet-stream)
2014-05-03 17:01 UTC, eb1
Details
Disassembler output from assembly compiled with Mono 2.10.9 (1.60 KB, application/octet-stream)
2014-05-03 17:01 UTC, eb1
Details
Sample interface code (110 bytes, text/x-csharp)
2014-05-03 17:02 UTC, eb1
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

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!