MONO Malfunctions?
Here is a piece of code I wrote that fails in running when compiled by MONO. I checked it carefully according to the language specification I have known, and couldn't find any explanation for the failure. I didn't believe it is the final result, and turned to VS to have a try. The program unsurprisingly passed with intended result. And therefore the code is what can distinguish MONO and VS (of the version I am using). The only problem here is whether this distinction is a critical misinterpretation of the language on MONO's side or it's just that I'm using the language feature in an too unconventional and excessive way.
(The following is a simplified test program that can properly demonstrate the problem, Mar.27,2009)
The result by VisualStudio:
: Test 0
: item A generated
: Test 1
: item A generated
请按任意键继续. . .
The result of the program compiled by MONO:
: Test 0
Error:
System.TypeLoadException: “QTest.MonoGenericTest+GEnumerator1`1[T]”上的 Generi
cArguments[0] (“T”)与类型参数“T”的约束冲突。
在 QTest.MonoGenericTest.GEnumerator1`1.<IEnumerable.GetEnumerator>c__Iterato
r0.MoveNext()
在 QTest.MonoGenericTest.Main(String[] args)
: Test 1
: item A generated
As the exception indicates, the MONO runtime framework regards the type parameter passed into GEnumerator (A in this case) from as conflicting with the type constraint (specified by the clause initated with the 'where' keyword). I suspect there is some deficiencies in MONO's runtime type management (as different to C++, C#'s generic types are generally expanded at runtime, this is definitely the reason why there's no error message given out by the compiler)