I did the same but it throwing the error.. I dont know what I am making
mistake here . All my application are 3.5 .net version,
Please find actual CS file which I am trying to serialize.
On Wed, 21 Aug 2019 at 14:06, Marc Gravell <[email protected]> wrote:
> K, I took the tiny bit of code you posted, and added something that uses
> it with XmlSerializer, which basically meant implementing the interface
> (with NIEs) and adding:
>
> using System;
> using System.Xml.Serialization;
> using pb = global::Google.Protobuf;
> using pbr = global::Google.Protobuf.Reflection;
>
> static class Program
> {
> static void Main()
> {
> var ser = new XmlSerializer(typeof(ClientIdentifier));
> var obj = new ClientIdentifier();
> ser.Serialize(Console.Out, obj);
> }
> }
>
> ---
>
> And here's the thing: it works fine! So: if anyone is going to be able to
> help you here, you're going to need to meet us half way, by *showing us the
> code that doesn't work*.
>
> On Wed, 21 Aug 2019 at 07:05, Arun <[email protected]> wrote:
>
>>
>> I am not able to initialize XmlSerializer class itself. It is failing
>> saying "static Types cannot be serialized "
>>
>> On Wed, 21 Aug 2019 at 00:20, Marc Gravell <[email protected]>
>> wrote:
>>
>>> Can you show any of your XmlSerializer code here, so can understand it?
>>> I wouldn't expect the presence of a static type to break XmlSerializer, I
>>> admit! But also: protobuf code doesn't usually guarantee anything other
>>> than that it should work with the corresponding protobuf library.
>>>
>>> On Tue, 20 Aug 2019, 06:32 arun kumar, <[email protected]> wrote:
>>>
>>>> @Marc Gravell,
>>>>
>>>> I auto-generated ".cs" files from each ".proto" file. . Whereever a
>>>> message declared inside another message in proto, auto-generated cs file is
>>>> generated as " Nested Types " and Types class is generated as static. (I
>>>> guess , its how the generator defined)
>>>>
>>>> And, I am trying to convert my xml data into CS object using
>>>> XMLSerializer , it complains
>>>>
>>>> There was an error reflecting type 'SCL.PC.ClientIdentifier'. --->
>>>>> System.InvalidOperationException: SCL.PC.ClientIdentifier+Types cannot be
>>>>> serialized. Static types cannot be used as parameters or return types.
>>>>
>>>>
>>>> All I am trying to do is ,
>>>>
>>>> Converting XML data --> CS Object (IMessage) --> proto buf Serialize
>>>>> into stream
>>>>
>>>>
>>>>
>>>> Is there any way, to convert the xml data to IMessageObject.. I can see
>>>> MessageParser has ParseJson object. Likewise, anything available for xml ?
>>>>
>>>>
>>>> var serializer = new XmlSerializer(typeof(SCL.PC.ClientIdentifier));
>>>>
>>>> Auto-Generated CS File :
>>>>
>>>> public sealed partial class ClientIdentifier :
>>>> pb::IMessage<ClientIdentifier> {
>>>> private static readonly pb::MessageParser<ClientIdentifier> _parser
>>>> = new pb::MessageParser<ClientIdentifier>(() => new ClientIdentifier());
>>>> private pb::UnknownFieldSet _unknownFields;
>>>> [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
>>>> public static pb::MessageParser<ClientIdentifier> Parser { get {
>>>> return _parser; } }
>>>>
>>>> ---
>>>>
>>>> #region Nested types
>>>> /// <summary>Container for nested types declared in the
>>>> ClientIdentifier message type.</summary>
>>>> [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
>>>> public static partial class Types {
>>>> public enum Context {
>>>> /// <summary>
>>>> /// The client's identifier consists of a functional identifier
>>>> (FID) in big-endian format. Valid values range from 0x00000000 to
>>>> 0xFFFFFFFF.
>>>> /// </summary>
>>>> [pbr::OriginalName("CFID")] Cfid = 0,
>>>> /// <summary>
>>>> /// The client's identifier consists of an ASCII-encoded serial
>>>> number.
>>>> /// </summary>
>>>> [pbr::OriginalName("CSN")] Csn = 1,
>>>> }
>>>>
>>>> }
>>>> #endregion
>>>>
>>>> }
>>>>
>>>> #endregion
>>>>
>>>>
>>>> On Monday, 19 August 2019 19:56:45 UTC+5:30, Marc Gravell wrote:
>>>>>
>>>>> And can we see some code that actually demonstrates this problem? That
>>>>> would really help here.
>>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Protocol Buffers" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/protobuf/a6a61e73-3253-4191-b2a0-27cb63d26bde%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/protobuf/a6a61e73-3253-4191-b2a0-27cb63d26bde%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>
>>
>> --
>> -- Arun
>>
>>
>
> --
> Regards,
>
> Marc
>
--
-- Arun
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/protobuf/CAG5mLyvdRnVxqvh7d%2BcUFwcgZhL3oPn2jtXGxV%3De%3Dtp%3DWxN5PQ%40mail.gmail.com.
// <auto-generated>
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SCL_PC_ClientIdentifier.proto
// </auto-generated>
#pragma warning disable 1591, 0612, 3021
#region Designer generated code
using pb = global::Google.Protobuf;
using pbc = global::Google.Protobuf.Collections;
using pbr = global::Google.Protobuf.Reflection;
using scg = global::System.Collections.Generic;
namespace SCL.PC {
/// <summary>Holder for reflection information generated from
SCL_PC_ClientIdentifier.proto</summary>
public static partial class SCLPCClientIdentifierReflection {
#region Descriptor
/// <summary>File descriptor for SCL_PC_ClientIdentifier.proto</summary>
public static pbr::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbr::FileDescriptor descriptor;
static SCLPCClientIdentifierReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"Ch1TQ0xfUENfQ2xpZW50SWRlbnRpZmllci5wcm90bxIGU0NMLlBDInIKEENs",
"aWVudElkZW50aWZpZXISMQoHY29udGV4dBgBIAEoDjIgLlNDTC5QQy5DbGll",
"bnRJZGVudGlmaWVyLkNvbnRleHQSDQoFdmFsdWUYAiABKAwiHAoHQ29udGV4",
"dBIICgRDRklEEAASBwoDQ1NOEAFiBnByb3RvMw=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
new
pbr::GeneratedClrTypeInfo(typeof(global::SCL.PC.ClientIdentifier),
global::SCL.PC.ClientIdentifier.Parser, new[]{ "Context", "Value" }, null,
new[]{ typeof(global::SCL.PC.ClientIdentifier.Types.Context) }, null)
}));
}
#endregion
}
#region Messages
/// <summary>
/// This message describes the client identifier used when creating and
querying for sessions.
/// </summary>
public sealed partial class ClientIdentifier : pb::IMessage<ClientIdentifier>
{
private static readonly pb::MessageParser<ClientIdentifier> _parser = new
pb::MessageParser<ClientIdentifier>(() => new ClientIdentifier());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<ClientIdentifier> Parser { get { return
_parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return
global::SCL.PC.SCLPCClientIdentifierReflection.Descriptor.MessageTypes[0]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public ClientIdentifier() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public ClientIdentifier(ClientIdentifier other) : this() {
context_ = other.context_;
value_ = other.value_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public ClientIdentifier Clone() {
return new ClientIdentifier(this);
}
/// <summary>Field number for the "context" field.</summary>
public const int ContextFieldNumber = 1;
private global::SCL.PC.ClientIdentifier.Types.Context context_ = 0;
/// <summary>
/// This field defines the namespace for the identifier's value.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public global::SCL.PC.ClientIdentifier.Types.Context Context {
get { return context_; }
set {
context_ = value;
}
}
/// <summary>Field number for the "value" field.</summary>
public const int ValueFieldNumber = 2;
private pb::ByteString value_ = pb::ByteString.Empty;
/// <summary>
/// This field contains the identifier's value as a sequence of bytes.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public pb::ByteString Value {
get { return value_; }
set {
value_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as ClientIdentifier);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Equals(ClientIdentifier other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (Context != other.Context) return false;
if (Value != other.Value) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
if (Context != 0) hash ^= Context.GetHashCode();
if (Value.Length != 0) hash ^= Value.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
if (Context != 0) {
output.WriteRawTag(8);
output.WriteEnum((int) Context);
}
if (Value.Length != 0) {
output.WriteRawTag(18);
output.WriteBytes(Value);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
if (Context != 0) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Context);
}
if (Value.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeBytesSize(Value);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(ClientIdentifier other) {
if (other == null) {
return;
}
if (other.Context != 0) {
Context = other.Context;
}
if (other.Value.Length != 0) {
Value = other.Value;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields,
other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(pb::CodedInputStream input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields,
input);
break;
case 8: {
context_ = (global::SCL.PC.ClientIdentifier.Types.Context)
input.ReadEnum();
break;
}
case 18: {
Value = input.ReadBytes();
break;
}
}
}
}
#region Nested types
/// <summary>Container for nested types declared in the ClientIdentifier
message type.</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static partial class Types {
public enum Context {
/// <summary>
/// The client's identifier consists of a functional identifier (FID)
in big-endian format. Valid values range from 0x00000000 to 0xFFFFFFFF.
/// </summary>
[pbr::OriginalName("CFID")] Cfid = 0,
/// <summary>
/// The client's identifier consists of an ASCII-encoded serial number.
/// </summary>
[pbr::OriginalName("CSN")] Csn = 1,
}
}
#endregion
}
#endregion
}
#endregion Designer generated code