Fix Winforms Designer serialization errors#4339
Merged
ChrisPulman merged 3 commits intoreactiveui:mainfrom Apr 26, 2026
Merged
Conversation
DesignerSerializationVisibility.Content caused multiple issues: * "The object 'viewModelControlHost1' returned null for the property 'ViewModel' but this is not allowed" when trying to save. * Setting values of some of the properties in the designer would produce code that would not compile. Instead of trying to please the designer just set DesignerSerializationVisibility.Hidden for non-primitive properties.
ChrisPulman
approved these changes
Apr 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
This PR fixes winforms designer serialization of
ViewModelControlHostandRoutedControlHostinReactiveUI.WinForms.What is the current behavior?
DesignerSerializationVisibility.Contentcauses multiple issues:The object 'viewModelControlHost1' returned null for the property 'ViewModel' but this is not allowedwhen trying to save (observed onnet481).DefaultContentin the designer produces code that does not compile (observed onnet10.0-windows10.0.19041.0).There are similar issues with other properties.
The attribute also makes no sense on
DefaultCacheViewsEnabled, because it's a static property.What is the new behavior?
Just turn off serialization for non-primitive properties.
This also makes things consistent with
ReactiveUserControl.ViewModel.Drop the attribute on
DefaultCacheViewsEnabled.What might this PR break?
This shouldn't break anything, the serialization did not work.
Please check if the PR fulfills these requirements
Other information:
Manual testing was performed on
net481andnet10.0-windows10.0.19041.0.DesignerSerializationVisibility.Contentwas introduced in #3933, probably because of a new analyzer error (WFO1000).Before that change the properties defaulted to
DesignerSerializationVisibility.Visible, but that did not make sense either.The only property that could actually be set in the designer was
DefaultContent, but doing that resulted in a fatalObjectDisposedExceptionwhen trying to reopen the designer.