jamescourtney / FlatSharp

Fast, idiomatic C# implementation of Flatbuffers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example03-SchemaFiles2 broken?

wolfman42 opened this issue · comments

I'm trying to use the latest 6.2.1 with build time compilation and am running into issue with generated Serializer Write and Parse methods. Tried building Example03-SchemaFiles2 and it doesn't compile with .NET 6.

The code in SchemaFilesExample2.cs line 58 expects this write method:
int bytesWritten = FooBarContainer.Serializer.Write(destination, container);

However, the GeneratedSerializer() has the following method signature which is inherited from ISerializer:
int Write<TSpanWriter>(TSpanWriter writer, Span<byte> destination, T item) where TSpanWriter : ISpanWriter;

Using the FlatBufferSerializer.Default serializer works, though:
int bytesWritten = FlatBufferSerializer.Default.Serialize(container, destination);

The write method you're mentioning is an extension method defined here:

public static int Write(this ISerializer serializer, byte[] buffer, object item)

I usually use extension methods on interfaces to reduce the need to implement boilerplate like this in each implementation.

I don't see any errors doing a clean build of the samples. Are you using VS, or some other IDE?

Thanks for getting back. This helped. I was missing using FlatSharp.Runtime; which then makes those extension methods available. Since the sample project is using global usings and the SchemaFilesExample2.cs doesn't have any using statements that wasn't immediately obvious. I guess I should have checked for that first, though.