问题
I've got some C# code that compiles fine under both mono and the Microsoft's .net compilers, but only runs on mono. The error message is (newlines added by me)
Unhandled Exception: System.TypeLoadException:
Could not load type 'Hasse.Groups.Heavy.Product.PowerGroup`1'
from assembly 'Hasse, Version=1.0.x.y, Culture=neutral, PublicKeyToken=null'
because it has recursive generic definition.
The type actually has a recursive generic definition, so my question is: why does it work with mono? [The code runs and produces the expected result]
Full source code is here: https://github.com/miniBill/Hasse
Reduced code which still crashes is here:
public class Group<T> : IWrappableGroup<WrapperGroup<T>> {}
public class WrapperElement<T> {}
public interface IWrappableGroup<U> {}
public class WrapperGroup<T> : Group<WrapperElement<T>> {}
class MainClass {
public static void Main(string[] args){
var ng = new Group<object>();
}
}
Here is proof that it works on mono: http://ideone.com/ZvA3I
回答1:
This is a known issue. It could be reported as a compiler error.
http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-335.pdf (page 129)
As for working in Mono, there are several places where Mono working is "broken" as far as the specs is concerned.
(Recursive lambdas are another exmaple of something that works in Mono that shouldn't)
来源:https://stackoverflow.com/questions/11295945/problems-with-recursive-generic-type-in-c-sharp