dotnet / dotnet/dotnet-api-docs

Code sample for System.ComponentModel.DesignerAttribute is wrong

Open
#3,726 0 comments 0 reactions 0 assignees View on GitHub
area-System.ComponentModel Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

Originally posted at: https://github.com/MicrosoftDocs/feedback/issues/2126

Describe the bug

On page: https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.designerattribute?view=netframework-4.8

[Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design.DLL",
typeof(IRootDesigner)),
DesignerCategory("Form")]
public class MyForm : ContainerControl {
// Insert code here.
}

The designer type should come from System.Design.DLL instead, or use Strong Type to reference it.

See: https://social.msdn.microsoft.com/Forums/vstudio/en-US/37d0819d-a3bf-46ad-ad99-cd93cadda81b/how-to-make-event-in-the-class-inherited-from-form?forum=csharpgeneral

To Reproduce

Create a "Windows Form Application" project.
Add a class FormBase inherited from System.Windows.Forms.Form. Use the described attributes from the documentation sample.
Change the default added Form1 to inherit from FormBase instead.
Switch to "Form Designer" in Form1. You should see error message regarding "instance" parameter is null because the referred DLL cannot be found.
Expected behavior
After change to use strong name as I described in MSDN forum (I actually copied the declaration from "Object Browser" for System.Windows.Forms.Form ), you should be able to use "Form Designer" in Form1.cs.

Desktop (please complete the following information):

Platform: .NET Framework v4.X

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.