Only a few people need the client program running on Microsoft Windows XP and other operating systems.This project is developed using Microsoft Visual Studio 2010 SP1 IDE. The back-end batch program copies the relevant source program to the Linux operating system, and then uses the xbuild command of Mono for compilation.
Everything was normal. However, one day when Mono's xbuild compilation was used, Mono C # compiler crashed. I was surprised and thought that the C # function not supported by Mono was used for code modification. Later, I found out that it was caused by a small bug of Mono C # compiler.
Bug descriptionWe have the following Tester. cs
1 static class Tester2 {3 static void Main() { }4 static void Test(decimal value = 0) { }5 }
This is a very simple C # program. Use the Microsoft C # compiler to compile everything normally. If Mono C # compiler 2.10.x is used for compilation, the Mono C # compiler will crash, as shown below:
ben@vbox:~/work> dmcs --versionMono C# compiler version 2.10.6.0ben@vbox:~/work> dmcs Tester.cswe can't encode valuetypes, we should have never reached this lineStacktrace: at (wrapper managed-to-native) System.Reflection.Emit.TypeBuilder.create_runtime_class (System.Reflection.Emit.TypeBuilder,System.Reflection.Emit.TypeBuilder) at System.Reflection.Emit.TypeBuilder.CreateType () at Mono.CSharp.TypeContainer.CloseType () at Mono.CSharp.ModuleContainer.CloseType () at Mono.CSharp.Driver.Compile () at Mono.CSharp.Driver.Main (string[]) at (wrapper runtime-invoke) .runtime_invoke_int_object (object,intptr,intptr,intptr) Native stacktrace: /usr/bin/mono() [0x493dda] /lib64/libpthread.so.0(+0xfd00) [0x7fdfb28eed00] /lib64/libc.so.6(gsignal+0x35) [0x7fdfb2583d95] /lib64/libc.so.6(abort+0x17b) [0x7fdfb25852ab] /usr/bin/mono() [0x5ccb4f] /usr/bin/mono() [0x5ccbd2] /usr/bin/mono() [0x4f594e] /usr/bin/mono() [0x4fcafe] /usr/bin/mono() [0x4fd4c4] /usr/bin/mono() [0x50273e] /usr/bin/mono() [0x50c3ff] [0x4119ebac]Debug info from gdb:=================================================================Got a SIGABRT while executing native code. This usually indicatesa fatal error in the mono runtime or one of the native librariesused by your application.=================================================================Abortedben@vbox:~/work>
Submit bugs to the Mono Development TeamI have submitted this bug to xamarin.com on, that is, Bug 4184: C # method optional argument is decimal type, C # compiler aborted .. Marek Safar, who handles the bug, replied: Already fixed in master and Mono 2.11. In my question, he further explained:
Master is the latest mono code from github.
Mono 2. 10. * has not been fixed. Upgrade to Mono 2.11
That is to say, this bug still exists in Mono C # compiler of Latest Stable Version. This bug was fixed in Alpha Version Mono C # compiler.
Current solutionThe following C # program will not cause Mono C # compiler 2.10.x to crash:
1 static class Tester2 {3 static void Main() { }4 static void Test(decimal value = 0m) { }5 }
Note that in the above source program, the optional parameter value of the decimal type of the Test method is initialized to 0 m rather than 0.
Check whether Mono C # compiler 2.11.1 solves this bug.To verify that Mono C # compiler 2.11.x has fixed this bug, I downloaded and installed mono 2.11.1, as shown below:
ben@vbox:~/src> wget http://download.mono-project.com/sources/mono/mono-2.11.1.tar.bz2ben@vbox:~/src> tar xjf mono-2.11.1.tar.bz2ben@vbox:~/src> cd mono-2.11.1ben@vbox:~/src/mono-2.11.1> ./configure --prefix=/opt/mono-2.11.1ben@vbox:~/src/mono-2.11.1> makeben@vbox:~/src/mono-2.11.1> sudo make installben@vbox:~/src/mono-2.11.1> cd ~/workben@vbox:~/work> /opt/mono-2.11.1/bin/mcs --versionMono C# compiler version 2.11.1.0ben@vbox:~/work> /opt/mono-2.11.1/bin/mcs Tester.csben@vbox:~/work>