Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Protobuf net protobuf网络引发泛型基类异常_Protobuf Net - Fatal编程技术网

Protobuf net protobuf网络引发泛型基类异常

Protobuf net protobuf网络引发泛型基类异常,protobuf-net,Protobuf Net,我有以下几点 [ProtoContract, ProtoInclude(50, typeof(DateRange)), ProtoInclude(51, typeof(IntRange))] public class Range<T> : IEquatable<Range<T>>, IEquatable<OpenRange<T>> where T: struct, IComparable<T> { [ProtoMemb

我有以下几点

[ProtoContract, ProtoInclude(50, typeof(DateRange)), ProtoInclude(51, typeof(IntRange))]
public class Range<T> : IEquatable<Range<T>>, IEquatable<OpenRange<T>> where T: struct, IComparable<T>
{
   [ProtoMember(1)]
   public T Start { get; set; }
   [ProtoMember(2)]
   public T End { get; set; }
}

[ProtoContract]
public class DateRange : Range<DateTime>
{
}

[ProtoContract]
public class IntRange : Range<int>
{
}
[ProtoContract,ProtoInclude(50,typeof(DateRange)),ProtoInclude(51,typeof(IntRange))]
公共类范围:IEquatable,IEquatable其中T:struct,IComparable
{
[原成员(1)]
公共T开始{get;set;}
[原成员(2)]
公共T端{get;set;}
}
[原始合同]
公共类日期范围:范围
{
}
[原始合同]
公共类内部网:范围
{
}
当我尝试序列化一个日期范围时,我得到以下错误

ProtoBuf.ProtoException:类型只能参与一个继承层次结构(DateRange) ---->System.InvalidOperationException:类型只能参与一个继承层次结构


在花了一些时间研究源代码之后,我很确定问题在于DateRange和IntRange在技术上都有不同的父级,因为Range!=范围。因此,我真的不确定我们应该如何处理仿制药。

从Marc链接的问题中获取细节,并创建了以下内容:

RuntimeTypeModel.Default[typeof (Range<DateTime>)]
   .AddSubType(50, typeof (DateRange));
RuntimeTypeModel.Default[typeof(Range<int>)]
   .AddSubType(50, typeof(IntRange));
RuntimeTypeModel.Default[typeof(Range)]
.AddSubType(50,typeof(DateRange));
RuntimeTypeModel.Default[类型(范围)]
.AddSubType(50,typeof(IntRange));

有点痛,但至少它起作用了

我想这和这里的问题是一样的:-你能检查一下并让我知道吗?这很有效。谢谢你的指点!酷-我会看看我能做些什么来推断这一点,因为它不断出现,文档将为我做这件事。。我找不到任何关于ProtoInclude的内容,除了这里的内容:)