This project is read-only.

Mono 1.2 Compatibility (part 2)

Topics: Developer Forum
Nov 30, 2006 at 9:42 PM
Assuming that the problem about TypeDescriptor is resolved changing this line:
T NewObject = (T)TypeDescriptor.CreateInstance(null, typeof(T), null, null);

in this way:
T NewObject = (T)Activator.CreateInstance(typeof(T));

now I'm trying to compile the code under mono 1.2.

It seems that mono 1.2 doesn't do its job because mono doesn't have yet implemented ICancelAddNew interface as specified here:

I've tryied to add this class to project:

using System;

namespace System.ComponentModel
public interface ICancelAddNew
void CancelNew(int itemIndex);

void EndNew(int itemIndex);

but the compiler crash during compiling with this error:

Unhandled Exception: System.InvalidOperationException: Operation is not valid due to the current state of the object
at System.Type.GetGenericTypeDefinition () 0x00000
at System.Reflection.Emit.TypeBuilder.GetGenericTypeDefinition () 0x00000
at Mono.CSharp.TypeManager.IsEqual (System.Type a, System.Type b) 0x00000
at Mono.CSharp.TypeManager.IsNestedChildOf (System.Type type, System.Type parent) 0x00000
at Mono.CSharp.SimpleName.IsNestedChild (System.Type t, System.Type parent) 0x00000
at Mono.CSharp.SimpleName.ResolveNested (IResolveContext ec, System.Type t) 0x00000
at Mono.CSharp.SimpleName.ResolveAsTypeStep (IResolveContext ec, Boolean silent) 0x00000
at Mono.CSharp.Expression.ResolveAsBaseTerminal (IResolveContext ec, Boolean silent) 0x00000
at Mono.CSharp.Expression.ResolveAsTypeTerminal (IResolveContext ec, Boolean silent) 0x00000
at Mono.CSharp.MemberBase.DoDefineBase () 0x00000
at Mono.CSharp.MethodOrOperator.DefineGenericMethod () 0x00000
at Mono.CSharp.MethodOrOperator.ResolveMembers () 0x00000
at Mono.CSharp.TypeContainer.DoResolveMembers () 0x00000
at Mono.CSharp.TypeContainer.ResolveMembers () 0x00000
at Mono.CSharp.TypeContainer.DefineType () 0x00000
at Mono.CSharp.Class.DefineType () 0x00000
at Mono.CSharp.TypeContainer.DefineNestedTypes () 0x00000
at Mono.CSharp.TypeContainer.DefineType () 0x00000
at Mono.CSharp.Class.DefineType () 0x00000
at Mono.CSharp.RootContext.ResolveTree () 0x00000
at Mono.CSharp.Driver.MainDriver (System.String[] args) 0x00000
at Mono.CSharp.Driver.Main (System.String[] args) 0x00000

I think that I've to post this error to mono developers group because I don't know how to skip it.
Dec 1, 2006 at 11:56 AM
Thanks Alessandro,
I cannot make the test right now on Mono.
Another solution is to use conditional compiling with #if clause to exclude ICancelAddNew from Mono compilation.
It would be interesting to know if Mono compiler define a preprocessor constant to distinguish Mono compilation from Framework compilation.
Dec 5, 2006 at 11:39 PM
Ok, it seems that I've found a solution.

Mono has a bug documented here ( When you specify generic parameter in partial classes, mono .net 2.0 compilator crashes. Bugzilla says that bug has been closed, but I think it's an error. In fact if I merge all partial classes in one unique class, Mono compiles correctly Raf Collection library.

Now if think I reopen that bug on Mono Bugzilla
Dec 6, 2006 at 5:06 PM
Great finding ALessandro. Thanks!
Dec 7, 2006 at 11:28 AM
Hi Alessandro, for the next release, I am going to replace the TypeDescriptor.CreateInstance with Activator.CreateInstance because this is compatible with both Mono and Compact Framework.
Could you make a test on mono and give me some feedback, please?