Closed AresZhu closed 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:
obj
directory in your project's folder to see if Flatsharp is emitting output. FlatSharp generated files look like Schema.fbs.generated.cs
.dotnet FlatSharp.Compiler.dll
)xaml
files. It might be the case that this is somehow not playing nicely with FlatSharp's MSBuild targets. You might try moving the FlatBuffer schema into its own project that is just a normal Class Library, and then reference that from your WPF app. This way FlatSharp runs before WPF.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.
@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
Thanks for sharing the sample! I will take a look this weekend.
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:
Use the FlatSharp compiler in a separate assembly (NET Standard DLL) that your WPF application references. I know you said that this wasn't ideal, but such dependencies are transitive and shouldn't be too bad. The only things you need are FlatSharp.Compiler
(build-time only reference), and FlatSharp.Runtime
(few dependencies).
Otherwise, if your schemas are simple and you don't need FBS files, you can use Attribute-based serialization. You just need the FlatSharp
and FlatSharp.Runtime
packages in this mode.
Finally, if those don't work and you really need to use FBS files (maybe your project is doing something with other languages or whatnot), then consider using the FlatSharp Compiler directly (it's just a command line tool), and tell it to emit output to your WPF project as a prebuild step. You can find the command line syntax from the build output of your current example (dotnet FlatSharp.Compiler.dll
)
Sorry I'm not any more help here.
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.
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!
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:
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?)