1

DisplayName and Description attributes are being ignored for my user control properties, but not Category.
Pretty much the same question as this, except that in my case the proposed answers do not work.

My code:

[DisplayName("Custom String"),
  Category("Custom Properties"),
  Description("String to display.")]
public string CustomString
{
    get { return customString; }
    set { customString = value; }
}
private string customString;

Properties window, showing that only the Category Attribute is working.

EDIT2 --------------------

Different webforms project, new user control created from scratch with same code (different values). Same results as before, only Category is applied.

public partial class AttributedUserControl : System.Web.UI.UserControl
{
    [DisplayName("New Control Text"),
    Category("New control Properties"),
    Description("Text to show inside the user control.")]
    public string TextString
    {
        get { return _TextString; }
        set { _TextString = value; }
    }
    private string _TextString;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

  • Visual Studio Professional 2015 - Version 14.0.25431.01 Update 3
  • .NET Framework 4.7.03056
  • How is a string property a User Control? – Ňɏssa Pøngjǣrdenlarp Jan 04 '19 at 18:00
  • Code works. Did you rebuild your solution after adding the information? – LarsTech Jan 04 '19 at 18:05
  • I am unconvinced that you are running the code you think you're running. Try modifying the Category value to see if that reflected in the property grid. If it doesn't then you're not using the compiled user control you think you're using... Other than that, those attributes are correct and should work... – Jazimov Jan 04 '19 at 23:52
  • @LarsTech I used the Clean and Rebuild commands for both the project and solution, only changes to Category apply. – TestNameDefault Jan 07 '19 at 09:33
  • @Jazimov Please read my reply to LarsTech. – TestNameDefault Jan 07 '19 at 09:34
  • Don't know what you are doing different. I take your code and the property grid shows the description, etc. – LarsTech Jan 07 '19 at 15:48
  • @TestNameDefault: Are you giving us the exact quoted strings you show in your example above? I ask because it's possible that your strings have illegal characters in them and we can't see those. Are you using exactly what you posted above??? – Jazimov Jan 07 '19 at 16:35
  • @Jazimov I am. I copy-pasted my code and made sure not to use any non-alphanumeric characters for those attributes. Doesn't matter what string I provide it, only the changes to Category are applied. It's a bit annoying, because this feature would have been great to avoid having to check the code-behind files for what each property does... – TestNameDefault Jan 07 '19 at 17:28
  • There is nothing wrong with your attributes code. There might be something you're not telling us--not that you're hiding something--but perhaps that you're not revealing all you need to reveal. You've shown a snippet above. Can you reduce your code to the bare minimum by creating a brand-new user control that uses the only the snippet shown above and see what happens? If that also doesn't work, can you upload the compiled user control? – Jazimov Jan 07 '19 at 20:01
  • @Jazimov Only thing that comes to mind is that it is a c# webforms project. I also edited the post after trying out a brand new user control in a different project, with the same results. – TestNameDefault Jan 08 '19 at 09:47

1 Answers1

0

You have found a bug. I created both a server control and a user control using Visual Studio 2017 and discovered that the System.ComponentModel.DescriptionAttribiute (i.e, [Description("My Description")]) does not work. I also discovered that the System.ComponentModel.DisplayName (i.e, [DisplayName("My Description")]) does not work. When I say "does not work", I mean that the property grid does not display the description at the bottom of the property grid window, as it should. No matter what you set as the Description attribute, only the property name string itself will appear in the description area of the property grid.

I suggest posting this issue to Microsoft. It is very frustrating, but you're doing nothing wrong. I have extensive experience writing Winforms controls and designers, and these attributes work in the Winforms space.

FWIW, other attributes, such as [DefaultValue("Test")], work just fine.

I wish I could report better news. You can accept this answer or try to start a bounty on this question, if you're eligible to do that. Otherwise, I invite any other experts to weigh-in.

Jazimov
  • 12,626
  • 9
  • 52
  • 59
  • I'll accept yours as the answer for now. Thank you for your time. – TestNameDefault Jan 08 '19 at 17:09
  • Thanks. I would have verified your code earlier within Visual Studio, but I know that those attributes work for Winforms because I used them nearly daily in my work. Once you mentioned Webforms, I decided to investigate. At first I thought that maybe there was a problem only with user controls, but when I saw the same issue exists for server controls, I knew there was a bona fide issue. It's surprising that there's not more written about this but Microsoft does break things from time-to-time so it likely is a framework-code issue rather than a problem with a particular version of the IDE. – Jazimov Jan 08 '19 at 19:54