jamescourtney / FlatSharp

Fast, idiomatic C# implementation of Flatbuffers
Apache License 2.0
497 stars 50 forks source link

Issue with init-only property when generating FlatSharp schema in .NET 6 #414

Closed VladimirMit closed 9 months ago

VladimirMit commented 9 months ago

Hello,

I've encountered an issue when trying to generate a FlatSharp schema in a .NET 6 project. The problem seems to be related to the use of init-only properties.

When attempting to generate the schema, the process fails with an error stating that it cannot find 'System.Runtime.CompilerServices.IsExternalInit'. This issue only occurs when I'm using .NET 6, and it worked fine with .NET Framework 4.8.

Here is the error message I'm getting: "FlatSharp compilation error: error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported, Context = "init { checked { this.__index0Value = value; } }"

I should note that the schema classes are located in netstandard2.0 assemblies. I tried setting multi-targeting to include .NET 6, but this did not resolve the issue.

FlatSharp 6.3.1 FlatSharp.Runtime 6.3.1

I'm not sure if this is a bug or if I'm missing something in my setup. Any assistance or guidance would be greatly appreciated.

Thank you.

jamescourtney commented 9 months ago

I'll certainly take a look at this and make sure that current versions of FlatSharp don't suffer from this.

However, please keep in mind that FlatSharp 6.X is out of support and won't be getting any future updates. You can find the full changelog for 7.0.0 here.

If you need help migrating to V7, I'll be happy to assist. The changes mostly involve using fbs files instead of C# classes and should generally be transparent.

jamescourtney commented 9 months ago

I've verified that FlatSharp 7 does not have this issue.

While FlatSharp 6 should support this, you need to make sure that you are using a version of C# and dotnet that supports init properties.