I'm now playing with .NET Core Class Library projects and testing some code that I already have in a regular class library project targeting .NET Framework.
I installed the System.ComponentModel
NuGet package to use annotations in an enum
. Looks like it's not recognizing the annotation.
Here's what the enum looks like:
using System.ComponentModel;
public enum UserRole
{
[Description("Undefined")]
Undefined = 0,
[Description("Super User")]
SuperUser = 1,
[Description("Administrator")]
Admin = 2,
[Description("Regular User")]
RegUser = 4
}
The error I'm seeing is:
The type or namespace name 'DescriptionAttribute' could not be found (are you missing a using directive or assembly reference?)
The using System.ComponentModel
reference at the top is grayed out and looks like it's not being used at all.
Two questions:
P.S. The code is working perfectly in my class library project targeting .NET Framework 4.6.2. So I'm only transferring code that I know to be working into my new .NET Core Class Library project.
For DescriptionAttribute you need to use the System.ComponentModel.Primitives package (version 4.1 and above).
Here's a handy website that you can look up the packages / support for APIs: https://packagesearch.azurewebsites.net/?q=descriptionattribute