[Mono-bugs] [Bug 770901] New: CompileAssemblyFromSource crashes with Object reference not set to an instance of an object

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Jul 11 13:09:19 UTC 2012



           Summary: CompileAssemblyFromSource crashes with Object
                    reference not set to an instance of an object
    Classification: Mono
           Product: Mono: Compilers
           Version: 2.10.x
          Platform: All
        OS/Version: RHEL 6
            Status: NEW
          Severity: Critical
          Priority: P5 - None
         Component: C#
        AssignedTo: michael.miller at suse.com
        ReportedBy: nikki at trumphurst.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---

Created an attachment (id=498194)
 --> (http://bugzilla.novell.com/attachment.cgi?id=498194)
Source code for program above

User-Agent:       Mozilla/5.0 (Windows NT 5.2; WOW64) AppleWebKit/536.11
(KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11

Calling CompileAssemblyFromSource sometimes causes the compiler to crash. The
compiler error list gets corrupted with part of the compiler stack trace.

I have narrowed the problem down to produce a minimal program to reproduce the
bug. However, in the real life code, the compiler crashes with different error

Reproducible: Always

Steps to Reproduce:
Compile the following code, then run it:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Reflection;
using Microsoft.CSharp;

namespace MonoCompilerBug {
    class Program {
        static void Main(string[] args) {
            Dictionary<string, string> options = new Dictionary<string, string>
                    { "CompilerVersion", "v3.5" }
            CSharpCodeProvider icc = new CSharpCodeProvider(options);
            CompilerParameters cp = new CompilerParameters();
            cp.CompilerOptions = "/t:library /optimize
            cp.GenerateInMemory = true;
            CompilerResults cr = icc.CompileAssemblyFromSource(cp, @"namespace
MonoCompilerBug {
    public class ModelCode : ModelBase {
            if (cr.Errors.Count > 0) {
                System.Console.WriteLine("{0} Compile errors:",
                foreach (CompilerError error in cr.Errors) {
                    System.Console.WriteLine("{0}:{1}:{2}", error.Line,
error.Column, error.ErrorText);
            } else {
                System.Console.WriteLine("Compiled OK");

    public class ModelBase {
        public class Page<C> {

        public class PageDictionary<T, C>
            where T : ModelBase.Page<C>, new() {



Actual Results:  
2 Compile errors:
2:22:Object reference not set to an instance of an object
2:22:Only assignment, call, increment, decrement, and new object expressions
can be used as a statement

Expected Results:  
Compiled OK

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

More information about the mono-bugs mailing list