2012-08-05 17 views
1

我在.Net 4設置的VS2010中創建了一個示例應用程序。我正在嘗試ProtoBuf-Net擴展方法。然而,當我嘗試調用的GetValue extention,它拋出一個異常,說Protobuf-Net擴展方法不斷拋出異常

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() 

下面是我的原班與Extention支持。

[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也給了我同樣的異常

回答

1

確實。擴展數據是自v2重寫以來缺少的最後一個部分之一。正如你可以看到它是next on the roadmap,但實際上(時間可用性等),我必須優先考慮最常見的.NET場景。擴展數據並不是最常見的用法。 V1擁有完整的擴展數據API,而r280(IIRC)仍然可用。

一旦我瞭解了這一點,我不會預料到(之前曾經寫過這篇文章)它是一項巨大的工作,所以我希望它很快會在構建中。


編輯:這應該是從R565開始

+0

謝謝!我試過r280 NET 3.0版本。它似乎在工作。 – SysAdmin 2012-08-05 17:45:52

+0

如果你可以更新維基頁面的擴展名,這將有助於其他的太 – SysAdmin 2012-08-05 17:49:44

+0

@SysAdmin嘗試r565,只是更新 – 2012-08-08 10:22:58