[Mono-list] NullReferenceException while using gmcs 1.2.6.0 and -langversion:linq

Dan Shryock dan.shryock at gmail.com
Tue Jan 29 12:23:49 EST 2008


I ran into a NullReferenceException using the latest gmcs on the
following piece of code:

using System;
using System.Collections.Generic;

public class gmcsnre{

	public static void Main(string[] args){
		var dict = Dict<object>(Id => 1,Name => "User",Email => "user at example.com");
		foreach(var item in dict){
			Console.WriteLine(item.Key +" => "+item.Value);
		}
	}

	public static Dictionary<string, T> Dict<T>(params Func<string, T>[] args){
		var items = new Dictionary<string, T>();
		foreach(var func in args){
			var item = func(null);
			items.Add(func.Method.GetParameters()[0].Name, item);
		}
		return items;
	}
}

If I change the line at "var dict = ..." to be the following, I don't
receive the error.
var dict = Dict<object>(new Func<string,object>[]{Id => 1,Name =>
"User",Email => "user at example.com"});

This may have been fixed in svn, but I don't have the opportunity to
test it at the moment.  This isn't a big deal for me, I just wanted to
report it in case it was not yet known.

Using "gmcs -langversion:linq gmcsnre.cs" as my command line, the
error I am receiving is below:

Exception caught by the compiler while compiling:
   Block that caused the problem begin at: gmcsnre.cs(6,28):
                     Block being compiled: [gmcsnre.cs(6,47):,gmcsnre.cs(12,9):]
System.NullReferenceException: Object reference not set to an instance
of an object
Internal compiler error at gmcsnre.cs(6,28):: exception caught while
emitting MethodBuilder [gmcsnre::Main]

Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an object
  at Mono.CSharp.AnonymousMethodExpression.ImplicitStandardConversionExists
(System.Type delegate_type) [0x00000]
  at Mono.CSharp.Convert.ImplicitStandardConversionExists
(Mono.CSharp.Expression expr, System.Type target_type) [0x00000]
  at Mono.CSharp.Convert.ImplicitConversionExists
(Mono.CSharp.EmitContext ec, Mono.CSharp.Expression expr, System.Type
target_type) [0x00000]
  at Mono.CSharp.MethodGroupExpr.IsParamsMethodApplicable
(Mono.CSharp.EmitContext ec, System.Collections.ArrayList arguments,
Int32 arg_count, System.Reflection.MethodBase candidate, Boolean
do_varargs) [0x00000]
  at Mono.CSharp.MethodGroupExpr.IsParamsMethodApplicable
(Mono.CSharp.EmitContext ec, System.Collections.ArrayList arguments,
Int32 arg_count, Boolean do_varargs, System.Reflection.MethodBase&
candidate) [0x00000]
  at Mono.CSharp.MethodGroupExpr.IsParamsMethodApplicable
(Mono.CSharp.EmitContext ec, System.Collections.ArrayList arguments,
Int32 arg_count, System.Reflection.MethodBase& candidate) [0x00000]
  at Mono.CSharp.MethodGroupExpr.OverloadResolve
(Mono.CSharp.EmitContext ec, System.Collections.ArrayList Arguments,
Boolean may_fail, Location loc) [0x00000]
  at Mono.CSharp.Invocation.DoResolveOverload (Mono.CSharp.EmitContext
ec) [0x00000]
  at Mono.CSharp.Invocation.DoResolve (Mono.CSharp.EmitContext ec) [0x00000]
  at Mono.CSharp.Expression.Resolve (Mono.CSharp.EmitContext ec,
ResolveFlags flags) [0x00000]
  at Mono.CSharp.Expression.Resolve (Mono.CSharp.EmitContext ec) [0x00000]
  at Mono.CSharp.Assign.DoResolve (Mono.CSharp.EmitContext ec) [0x00000]
  at Mono.CSharp.Expression.Resolve (Mono.CSharp.EmitContext ec,
ResolveFlags flags) [0x00000]
  at Mono.CSharp.Expression.Resolve (Mono.CSharp.EmitContext ec) [0x00000]
  at Mono.CSharp.ExpressionStatement.ResolveStatement
(Mono.CSharp.EmitContext ec) [0x00000]
  at Mono.CSharp.StatementExpression.Resolve (Mono.CSharp.EmitContext
ec) [0x00000]
  at Mono.CSharp.Block.Resolve (Mono.CSharp.EmitContext ec) [0x00000]
  at Mono.CSharp.EmitContext.ResolveTopBlock (Mono.CSharp.EmitContext
anonymous_method_host, Mono.CSharp.ToplevelBlock block,
Mono.CSharp.Parameters ip, IMethodData md, System.Boolean&
unreachable) [0x00000]


More information about the Mono-list mailing list