I am trying to serialize and deserialize a protocol buffer message to and from an XPathDocument but it fails with an exception: ProtoBuf.ProtoException: Mismatched group tags detected in messageHow do I make this work?
I am using protobuf-net and my source code for reproducing it looks like this:
TestMsg.proto
option optimize_for = SPEED;
//*************************
message Test {
repeated A a = 1;
}
message A {
required string str = 1;
}
Progam.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.XPath;
using ProtoBuf;
using TestMsg;
namespace protocolbufferserialize
{
class Program
{
static void Main(string[] args)
{
Test t = new Test();
XPathDocument xmldoc = Serialize(t);
Test t1 = Serialize(xmldoc);
}
public static XPathDocument Serialize(Test wro)
{
XPathDocument xmlDoc = null;
Serializer.PrepareSerializer<Test>();
XmlSerializer x = new XmlSerializer(wro.GetType());
using (MemoryStream memoryStream = new MemoryStream())
{
using (TextWriter w = new StreamWriter(memoryStream))
{
x.Serialize(w, wro);
memoryStream.Position = 0;
xmlDoc = new XPathDocument(memoryStream);
}
}
return xmlDoc;
}
public static Test Serialize(XPathDocument xmlDoc)
{
Test t = null;
Serializer.PrepareSerializer<Test>();
XmlSerializer x = new XmlSerializer(xmlDoc.GetType());
using (MemoryStream memoryStream = new MemoryStream())
{
using (TextWriter w = new StreamWriter(memoryStream))
{
x.Serialize(w, xmlDoc);
memoryStream.Position = 0;
t = Serializer.Deserialize<Test>(memoryStream);
}
}
return t;
}
}
}
--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/protobuf/-/EXMM0ECi3McJ.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.
I want to use XPath on my messages so need to move to and from XML.
--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/protobuf/-/mKbJ7GITXV0J.