'protobuf Error when converting List<> to stream: No serializer for type
I'm trying to do something that I think should be simple: Convert a List<object> into a stream.
using ProtoBuf;
using System.Collections.Generic;
using System.IO;
namespace ConsoleApp1
{
class MyObject
{
public string Prop1 { get; set; }
public string Prop2 { get; set; }
public string Prop3 { get; set; }
}
class Program
{
static void Main(string[] args)
{
List<MyObject> myObjects = new();
myObjects.Add(new() { Prop1 = "foo1", Prop2 = "bar1", Prop3 = "something1" });
myObjects.Add(new() { Prop1 = "foo2", Prop2 = "bar2", Prop3 = "something2" });
myObjects.Add(new() { Prop1 = "foo3", Prop2 = "bar3", Prop3 = "something3" });
using var stream = new MemoryStream();
Serializer.Serialize(stream, myObjects); // Error is here
byte[] bytes = stream.ToArray();
}
}
}
This is the error:
System.InvalidOperationException HResult=0x80131509 Message=No serializer for type ConsoleApp1.MyObject is available for model (default) Source=protobuf-net.Core
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
