1

我在 VS2010 中使用 .Net 4 设置创建了一个示例应用程序。我正在尝试 ProtoBuf-Net 扩展方法。但是,无论何时,我尝试调用 GetValue 扩展,它都会抛出一个异常说

Method or operation is not implemented

堆栈跟踪:

   at ProtoBuf.ExtensibleUtil.GetExtendedValues[TValue](IExtensible instance, Int32 tag, DataFormat format, Boolean singleton, Boolean allowDefinedTag)
   at ProtoBuf.Extensible.TryGetValue[TValue](IExtensible instance, Int32 tag, DataFormat format, Boolean allowDefinedTag, TValue& value)
   at ProtoBuf.Extensible.TryGetValue[TValue](IExtensible instance, Int32 tag, DataFormat format, TValue& value)
   at ProtoBuf.Extensible.GetValue[TValue](IExtensible instance, Int32 tag, DataFormat format)
   at ProtoBuf.Extensible.GetValue[TValue](IExtensible instance, Int32 tag)
   at PhoneBookData.PhoneBookSerializer.Serialize(PhoneBookProto phData) in E:\project\PhoneBook\Source\PhoneBookData\PhoneBookSerializer.cs:line 14
   at ConsoleApplication1.Program.Main(String[] args) in E:\project\PhoneBook\Source\ConsoleApplication1\Program.cs:line 23
   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

下面是我的带有扩展支持的 Proto 类。

[ProtoContract]
public class PhoneBookProto : Extensible
{
    [ProtoMember(1, IsRequired=true)]
    public string Name { get; set; }
    [ProtoMember(2)]
    public string Email { get; set; }
    [ProtoMember(3)]
    public AddressProto Address { get; set; }
    [ProtoMember(4,IsRequired=true)]
    public string PhoneNumber { get; set; }
}

[ProtoContract]
public class AddressProto
{
    [ProtoMember(1)]
    public string Line1 { get; set; }
    [ProtoMember(2)]
    public string Line2 { get; set; }
}

我究竟做错了什么。我参考了可供下载的最新 protobuf 版本 (561)。下面是我的代码,它不断崩溃。

Extensible.AppendValue<int>(phData, 5, 10);
Extensible.GetValue<int>(phData, 5);

编辑 其他旧版本的 protobuf 也给了我同样的例外

4

1 回答 1

1

确实。扩展数据是自 v2 重写以来丢失的最后一部分。正如您所看到的,它是路线图上的下一个,但实际上(时间可用性等)我必须首先优先考虑最常见的 .NET 方案。扩展数据根本不是最常见的用法。V1 具有完整的扩展数据 API,并且 r280 (IIRC) 仍然可用。

一旦我开始研究这个,我不认为(之前写过一次)它是一项巨大的工作,所以我希望它很快就会在构建中。


编辑:这应该从 r565 开始可用

于 2012-08-05T17:37:23.050 回答