Bug 4994 - gmcs/dmcs crashes with Unhandled Exception: System.ArgumentException
Summary: gmcs/dmcs crashes with Unhandled Exception: System.ArgumentException
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2012-05-10 06:17 UTC by joerg.meyer
Modified: 2012-05-17 16:43 UTC (History)
1 user (show)

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

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 joerg.meyer 2012-05-10 06:17:50 UTC
I tried to compile a .NET library with mono which failed with the following error:

Internal compiler error at ########.cs(###,##):: exception caught while emitting MethodBuilder [<##########>c__Iterator0::Dispose]

Unhandled Exception: System.ArgumentException: Trying to emit a local from a different ILGenerator.
  at System.Reflection.Emit.ILGenerator.Emit (OpCode opcode, System.Reflection.Emit.LocalBuilder local) [0x00000] in <filename unknown>:0
  at Mono.CSharp.EmitContext.Emit (OpCode opcode, System.Reflection.Emit.LocalBuilder local) [0x00000] in <filename unknown>:0
  at Mono.CSharp.LocalVariable.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.VariableReference.EmitLoad (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.VariableReference.Emit (Mono.CSharp.EmitContext ec, Boolean leave_copy) [0x00000] in <filename unknown>:0
  at Mono.CSharp.TemporaryVariableReference.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.Lock.EmitFinallyBody (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.ExceptionStatement.EmitForDispose (Mono.CSharp.EmitContext ec, Mono.CSharp.Iterator iterator, Label end, Boolean have_dispatcher) [0x00000] in <filename unknown>:0
  at Mono.CSharp.Iterator.EmitDispose (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.IteratorStorey+DisposeMethod+DisposeMethodStatement.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.Block.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.MethodData.Emit (Mono.CSharp.DeclSpace parent) [0x00000] in <filename unknown>:0
  at Mono.CSharp.MethodOrOperator.Emit () [0x00000] in <filename unknown>:0
  at Mono.CSharp.Method.Emit () [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: Trying to emit a local from a different ILGenerator.
  at System.Reflection.Emit.ILGenerator.Emit (OpCode opcode, System.Reflection.Emit.LocalBuilder local) [0x00000] in <filename unknown>:0
  at Mono.CSharp.EmitContext.Emit (OpCode opcode, System.Reflection.Emit.LocalBuilder local) [0x00000] in <filename unknown>:0
  at Mono.CSharp.LocalVariable.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.VariableReference.EmitLoad (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.VariableReference.Emit (Mono.CSharp.EmitContext ec, Boolean leave_copy) [0x00000] in <filename unknown>:0
  at Mono.CSharp.TemporaryVariableReference.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.Lock.EmitFinallyBody (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.ExceptionStatement.EmitForDispose (Mono.CSharp.EmitContext ec, Mono.CSharp.Iterator iterator, Label end, Boolean have_dispatcher) [0x00000] in <filename unknown>:0
  at Mono.CSharp.Iterator.EmitDispose (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.IteratorStorey+DisposeMethod+DisposeMethodStatement.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.Block.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0
  at Mono.CSharp.MethodData.Emit (Mono.CSharp.DeclSpace parent) [0x00000] in <filename unknown>:0
  at Mono.CSharp.MethodOrOperator.Emit () [0x00000] in <filename unknown>:0
  at Mono.CSharp.Method.Emit () [0x00000] in <filename unknown>:0


$uname -a
Linux monotest 3.0.0-17-server #30-Ubuntu SMP Thu Mar 8 22:15:30 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

$mono --version
Mono JIT compiler version 2.10.5 (Debian 2.10.5-1)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            Included Boehm (with typed GC and Parallel Mark)

$gmcs --version
Mono C# compiler version 2.10.5.0


I can reproduce the error with this program using gmcs or dmcs:

using System.Collections.Generic;

namespace Test {
    public static class Program {
        public static void Main() { }
        public static IEnumerable<object> EnumDevices()
        {
                lock(new object())
                {
                        yield return null;
                        yield break;
                }
        }
    }
}
Comment 1 Marek Safar 2012-05-17 16:43:21 UTC
Fixed in master