我在 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 也给了我同样的例外