jamescourtney / FlatSharp

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

Cannot find class for WPF project when using FlatSharpCompiler #293

Closed AresZhu closed 2 years ago

AresZhu commented 2 years ago

I created a simple WPF project, added FlatSharp.Compiler to the project and defined a simple fbs schema. fbs classes can be generated correctly based on the fbs schema, but the project failed to compile due to a class cannot be found. I use ReSharp as my IDE. below is the basic project information. SDK: .NET CORE 6.0 Type: WPF Application. Framework: net6.0

fbs schema:

namespace Example;

table User { Name: string; HashedPassword: string; }

When I try to use the namespace Example in project class, say in App.xml.cs, it reports compile error. App.xaml.cs(1, 7): [CS0246] The type or namespace name 'Example' could not be found (are you missing a using directive or an assembly reference?)

jamescourtney commented 2 years ago

It looks like your IDE isn't picking up the generated file. Unfortunately, there isn't quite enough information here for me to help you, but I have a couple of suggestions:

Finally, if all else fails, please feel free to share a full repo that shows the problem and I'll be happy to take a deeper dive.

AresZhu commented 2 years ago

@jamescourtney Thanks for your detailed explanations. 1 and 2 are all good. re 3, I think to create a new project definitely can solve this kind of issue, but it will make my project complicated. So I just created a repo which has this kind of issue. https://github.com/AresZhu/FlatSharpInWPF

jamescourtney commented 2 years ago

Thanks for sharing the sample! I will take a look this weekend.

jamescourtney commented 2 years ago

I've looked through this and can confirm that WPF is indeed interfering with FlatSharp's compiler targets. I confess that I'm not at all an expert in how MSBuild and target files work together, and what about WPF is different. I can only conclude that since WPF is generating code, it's somehow causing the build not to "see" FlatSharp's files.

Here are my suggestions:

Sorry I'm not any more help here.

AresZhu commented 2 years ago

Hi @jamescourtney Thanks for your time helping dig into this issue, your suggestions are quite helpful, option 3 makes more sense for me. will implement it in my project. thanks again.

jamescourtney commented 2 years ago

Glad I could help, though I admit I'm not satisfied with the "resolution" here. I'm also not such a glutton for punishment that I want to spend time trying to debug MSBuild targets.

If you ever do find anything around this (or something else), please feel free to contribute it back to FlatSharp. I sincerely welcome any contributions!