Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Build fails when using ReactiveWindow with System.Text.Json source generation #3255

Open
database64128 opened this issue May 1, 2022 · 5 comments
Labels

Comments

@database64128
Copy link

database64128 commented May 1, 2022

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 #3255 (comment) 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

  1. Create a WPF project targeting .NET 6, add reference to RxUI and create MainWindowViewModel.
  2. Build succeeds.
  3. Replace WPF's Window with RxUI's ReactiveWindow.
  4. Build fails.
  5. Add package reference to STJ.
  6. Build succeeds.

Reproduction repository

https://github.com/database64128/WPFRxUISTJSourceGenerationMinimalReproduction

Expected behavior

Build succeeds.

ReactiveUI Version

18.0.10

@glennawatson
Copy link
Contributor

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.

@database64128
Copy link
Author

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: database64128/youtube-dl-wpf@51947e6.

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?

@glennawatson
Copy link
Contributor

Yeah, Can be best if you do that. I'd be concerned with a fody and source generator interop as well.

@database64128
Copy link
Author

Turns out it was unrelated to Fody. For some reason it can be fixed by referencing the STJ package: database64128/youtube-dl-wpf@f201304, even though my project was already targeting .NET 6.

@database64128
Copy link
Author

database64128 commented May 4, 2022

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:

  1. database64128/WPFRxUISTJSourceGenerationMinimalReproduction@1cfa42a: Fresh WPF app with STJ source generation: no issues
  2. database64128/WPFRxUISTJSourceGenerationMinimalReproduction@561c4c1: Add RxUI and use ReactiveObject: no issues
  3. database64128/WPFRxUISTJSourceGenerationMinimalReproduction@743bea9: Switch from WPF's Window to RxUI's ReactiveWindow: build fails.
  4. database64128/WPFRxUISTJSourceGenerationMinimalReproduction@b670587: 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...

@database64128 database64128 reopened this May 4, 2022
@database64128 database64128 changed the title [Bug]: Classes with [Reactive] decorated properties can't be used with System.Text.Json source generation [Bug]: Build fails when using ReactiveWindow with System.Text.Json source generation May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants