[Bug]: Build fails when using `ReactiveWindow` with `System.Text.Json` source generation
Describe the bug 🐞
~~When a class with [Reactive] decorated properties is used with System.Text.Json source generation, build fails with the following errors:~~
Update: See https://github.com/reactiveui/ReactiveUI/issues/3255#issuecomment-1117245316 instead.
CS0534: 'SettingsJsonSerializerContext' does not implement inherited abstract member 'JsonSerializerContext.GeneratedSerializerOptions.get'
CS0534: 'SettingsJsonSerializerContext' does not implement inherited abstract member 'JsonSerializerContext.GetTypeInfo(Type)'
Step to reproduce
- Create a WPF project targeting .NET 6, add reference to RxUI and create
MainWindowViewModel. - Build succeeds.
- Replace WPF's
Windowwith RxUI'sReactiveWindow. - Build fails.
- Add package reference to STJ.
- Build succeeds.
Reproduction repository
https://github.com/database64128/WPFRxUISTJSourceGenerationMinimalReproduction
Expected behavior
Build succeeds.
ReactiveUI Version
18.0.10
I seen this when your context isn't a partial class and decorated correctly. Check also the output window to see if the build failed.
There's also a strong argument not to have view models be directly serialisable.
I seen this when your context isn't a partial class and decorated correctly.
I believe it is correctly written and decorated. The whole change is in this commit: https://github.com/database64128/youtube-dl-wpf/commit/51947e6775689b1101514fd818d371a95816f454.
There's also a strong argument not to have view models be directly serialisable.
In this case it's not exactly a view model. The Settings class stores app settings. Inheriting ReactiveObject and decorating its properties with [Reactive] seems to be the easiest way to make certain parts of the app respond to setting changes. Maybe I should use a separate class for JSON serialization and deserialization?
Yeah, Can be best if you do that. I'd be concerned with a fody and source generator interop as well.
Turns out it was unrelated to Fody. For some reason it can be fixed by referencing the STJ package: https://github.com/database64128/youtube-dl-wpf/commit/f201304be75674630eb2fbea1419cd1f37dacff4, even though my project was already targeting .NET 6.
dotnet/runtime#68810
Turns out the issue was caused by ReactiveWindow. I made a minimal reproduction repo: https://github.com/database64128/WPFRxUISTJSourceGenerationMinimalReproduction. There are 4 commits:
- database64128/WPFRxUISTJSourceGenerationMinimalReproduction@1cfa42a81dc3a17de085f10bafccf9f24dbdb8b4: Fresh WPF app with STJ source generation: no issues
- database64128/WPFRxUISTJSourceGenerationMinimalReproduction@561c4c16469558c1d32aa55ed3ae23f4c210ca34: Add RxUI and use
ReactiveObject: no issues - database64128/WPFRxUISTJSourceGenerationMinimalReproduction@743bea978e39695e12d07bb08a5f3875ec38ff75: Switch from WPF's
Windowto RxUI'sReactiveWindow: build fails. - database64128/WPFRxUISTJSourceGenerationMinimalReproduction@b6705875106c04a5231243ac99da6fd05fa5d161: Add package reference to
System.Text.Json: build succeeds.
GitHub
Minimal reproduction of a bug that can only be triggered when using RxWindow together with STJ source generation in a WPF app. - GitHub - database64128/WPFRxUISTJSourceGenerationMinimalReproduction...