ReactiveUI: [BUG] InvalidProgramException when [Reactive] property with Nullable type is assigned null in member declaration
Describe the bug
When a Fody-woven [Reactive] property of nullable value type (Nullable<T> for some T) is assigned null directly in the member declaration, running the constructor results in an InvalidProgramException.
Steps To Reproduce
- Create a new WPF project.
- Add ReactiveUI and the Fody package.
- Add a Loaded event handler to the MainWindow window, and make the code mirror:
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) {
var z = new TestViewModel(); // <- "A"
}
}
public class TestViewModel : ReactiveObject {
[Reactive]
public int? Floopy { get; set; } = null;
}
- Run. The code will crash in location “A”. (The event doesn’t matter, but the exception would be caught by XAML construction and obscured if run in the window’s constructor.)
Expected behavior
For there not to be an issue. Assigning null happens to be redundant, and assigning other values does not seem to cause crashes. Nullable reference types are also not affected.
“Just don’t do that” is a perfectly reasonable workaround - but it took me an hour to narrow it down to this being the issue.
Environment
- OS: Windows
- Version 10
- Device: PC
- Reactive UI: 13.1.1
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (6 by maintainers)
The fody is going into maintenance-only mode at the moment while we work on a new project which will replace the functionality in general. Keeping this open to track for the new project.