Mono C # a bug in the Compiler

Source: Internet
Author: User
Tags microsoft c visual studio 2010
Problem Source

One of my most recent projects was developed in C. This project is divided into the following parts:

  • MySQL 5.5.23 database running in SuSE Linux Enterprise Server 11 SP1.
  • The backend batch program running in the SuSE Linux Enterprise Server 11 SP1 operating system is automatically scheduled to run through corntab.
  • The ASP. Net 4 website runs on the Microsoft Windows Server 2003 R2 SP2 operating system. Most people access this website to use this project.
  • 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 description

We 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 Team

I 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 solution

The 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>

Sure enough.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.