Skip to content

Fix Winforms Designer serialization errors#4339

Merged
ChrisPulman merged 3 commits intoreactiveui:mainfrom
xackus:fix-viewhost-winforms-designer-errors
Apr 26, 2026
Merged

Fix Winforms Designer serialization errors#4339
ChrisPulman merged 3 commits intoreactiveui:mainfrom
xackus:fix-viewhost-winforms-designer-errors

Conversation

@xackus
Copy link
Copy Markdown
Contributor

@xackus xackus commented Apr 26, 2026

What kind of change does this PR introduce?

This PR fixes winforms designer serialization of ViewModelControlHost and RoutedControlHost in ReactiveUI.WinForms.

What is the current behavior?

DesignerSerializationVisibility.Content causes multiple issues:

  • The object 'viewModelControlHost1' returned null for the property 'ViewModel' but this is not allowed when trying to save (observed on net481).
  • Setting DefaultContent in the designer produces code that does not compile (observed on net10.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

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Other information:

Manual testing was performed on net481 and net10.0-windows10.0.19041.0.

DesignerSerializationVisibility.Content was 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 fatal ObjectDisposedException when trying to reopen the designer.

xackus and others added 3 commits April 26, 2026 18:27
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 ChrisPulman enabled auto-merge (squash) April 26, 2026 19:06
@ChrisPulman ChrisPulman merged commit 2be6785 into reactiveui:main Apr 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants