jamescourtney / FlatSharp

Fast, idiomatic C# implementation of Flatbuffers
Apache License 2.0
510 stars 51 forks source link

Error generating model code when using namespace ending with FlatBuffer in .fbs file #406

Closed boris-holmes closed 11 months ago

boris-holmes commented 1 year ago

Hi team,

I am using FlatBuffer 7.3.0 (installed via nuget package) in VS 2022 in a .NET 6 library. I created a .fbs file for my schema, and my namespace in there is (not the final namespsace, just trialing at this point):

namespace MyOrganization.FlatSharp;

When building, I get this error: 1>C:\Source\...\obj\Debug\net6.0\FlatSharp.generated.cs(1855,101,1855,109): error CS0234: The type or namespace name 'Compiler' does not exist in the namespace 'MyOrganization.FlatSharp' (are you missing an assembly reference?)

Indeed the generated code I have references to FlatSharp namespace. And the compiler is getting confused, thinking it's referencing MyOrganization.FlatSharp whereas it should reference the FlatSharp namespace from the nugget library.

this.Name = FlatSharp.Compiler.Generated.CloneHelpers_023fb05e442b4a26a5ebcb4bfe3135cf.Clone(source.Name);

jamescourtney commented 1 year ago

This looks like a namespace resolution issue. I'll treat it as a bug. Basically, when you specify FlatSharp in your namespace, then the C# compiler will (by default) look for FlatSharp.Compiler under MyNamespace.FlatSharp.Compiler, which doesn't exist. I'll take a bug to try and change all code to be global::FlatSharp, but in the meantime, you should be able to solve this by changing FlatSharp to FlatBuffers in your FBS definition.

jamescourtney commented 11 months ago

Fixed in 7.4.0