Closed Jonasmarien closed 4 months ago
@Olina-Zhang Can your team please test this?
@Jonasmarien this issue can be resolved using Nuget: Microsoft.WinForms.Designer.SDK, and need to refactor the namespaces from System.ComponentModel.Design
to Microsoft.DotNet.DesignTools.Designers
, referring to blog: https://devblogs.microsoft.com/dotnet/custom-controls-for-winforms-out-of-process-designer/
Here is my updated app based on your steps: WinFormsApp22.zip
Video:
https://github.com/dotnet/winforms/assets/26474449/5e73df26-71fa-4ead-bbcc-7b3b4ae7fc2f
@Olina-Zhang Using the SDK does resolve the casting issue but causes another exception if I add the following to the serializer:
public class MySerializer : CodeDomSerializer
{
public override object Serialize(IDesignerSerializationManager manager, object value)
{
SerializeToExpression(manager, value);
return null;
}
}
Same happens when I try to call the GetExpression method, even though both are defined in CodeDomSerializerBase.
Any idea why this exception is thrown?
@Jonasmarien What about using component item in Winforms app directly?
This submission has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 14 days.
It will be closed if no further activity occurs within 7 days of this comment.
Environment
Version 17.9.7
.NET version
.NET 8
Did this work in a previous version of Visual Studio and/or previous .NET release?
No response
Issue description
When I create a custom CodeDomSerializer and specify it on a Component using the DesignerSerializerAttribute, a casting exception occurs whenever serialization is triggered in the Visual Studio Designer.
Project file
Steps to reproduce
Create a new WinForms project targeting .NET 8
Add a WinForms UserControl
Create a new MyComponent class which inherits
System.ComponentModel.Component
Create a new MySerializer class which inherits
System.ComponentModel.Design.Serialization.CodeDomSerializer
public class MySerializer : CodeDomSerializer { }
using System.ComponentModel; using System.ComponentModel.Design.Serialization;
[DesignerSerializer(typeof(MySerializer), typeof(CodeDomSerializer))] internal class MyComponent : Component { }