Problems with recursive generic type in c#(c#中递归泛型类型的问题)
问题描述
我有一些 C# 代码在 mono 和 Microsoft 的 .net 编译器下都能正常编译,但只能在 mono 上运行.错误信息是(我添加的换行符)
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]
完整的源代码在这里: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>();
}
}
这是它在单声道上工作的证据:http://ideone.com/ZvA3I
Here is proof that it works on mono: http://ideone.com/ZvA3I
推荐答案
这是一个 已知 问题.它可能被报告为编译器错误.
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(第 129 页)
至于在 Mono 中工作,就规范而言,有几个地方 Mono 工作被破坏"了.
As for working in Mono, there are several places where Mono working is "broken" as far as the specs is concerned.
(递归 lambdas 是另一个适用的例子不应该的单声道)
(Recursive lambdas are another exmaple of something that works in Mono that shouldn't)
这篇关于c#中递归泛型类型的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:c#中递归泛型类型的问题
基础教程推荐
- 如何激活MC67中的红灯 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- SSE 浮点算术是否可重现? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 XML 转换为通用列表 2022-01-01