I have attempted to recreate a simple Schema Registry sample based on the Microsoft.Azure.Data.SchemaRegistry.ApacheAvro sample. Unfortunately the serializer fails to serialize. I receive the following error: System.ArgumentException: 'Type Person is not supported for serialization operations.'
Any ideas?
Here is my schema from Azure Portal
{
"type": "record",
"name": "Person",
"namespace": "PersonSchema",
"fields": [
{
"name": "PersonId",
"type": "int"
},
{
"name": "PersonName",
"type": "string"
}
]
}
Here is my POCO class. I added the [Serializable] attribute but that did not help.
[Serializable]
public class Person
{
public int PersonId { get; set; }
public string PersonName { get; set; }
public Person()
{
}
}
Here is the code that creates SchemaRegistryClient and serializes my Person class instance using SchemaRegistryAvroObjectSerializer
internal void TestSchemaMethod()
{
var cred = new ClientSecretCredential("MY_TENANT_ID", "MY_CLIENT_ID", "MY_SECRET");
var schemaRegistryClient = new SchemaRegistryClient("MYNAMESPACE.servicebus.windows.net", cred);
using (var memoryStream = new MemoryStream())
{
var serializer = new SchemaRegistryAvroObjectSerializer(schemaRegistryClient, "TestDataSchema", new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true });
var id = 1;
var person = new Person() { PersonId = id, PersonName = $"SomeName{id}" };
serializer.Serialize(memoryStream, person, typeof(Person), CancellationToken.None);
}
}