.NET Standard portable library error with DescriptionAttribute

Viewed 500

I created a .NET Standard library that contains models that will be shared between .NET Framework apps and .NET Core apps.

I have an enum that uses DescriptionAttribute. Here's the enum that is inside the .NET Standard 1.5 library:

using System.ComponentModel;
public enum Foo
{
    [Description("Description A")]
    A,
    [Description("Description B")]
    B
}

To be able to use the DescriptionAttribute, I added System.ComponentModel.Primitives form a NuGet package.

Now in my .NET Framework app, I want to retrieve the description of the enum.

The implementation to get the description of the enum is different between .NET Core and .NET Framework. So in my .NET Framework 4.6.2 app, I have an extension GetDescription that resolves the description attribute of the enum and returns it like that:

public static string GetDescription(this Enum value)
{
    Type type = value.GetType();
    string name = Enum.GetName(type, value);
    if (name != null)
    {
        FieldInfo field = type.GetField(name);
        if (field != null)
        {
            DescriptionAttribute attr =
                   Attribute.GetCustomAttribute(field,
                     typeof(DescriptionAttribute)) as DescriptionAttribute;
            if (attr != null)
            {
                return attr.Description;
            }
        }
    }
    return null;
}

I get that error :

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.ComponentModel.Primitives, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

enter image description here

I tried to add the System.ComponentModel.Primitives and I still have the error.

EDIT

Here's my project's structure:

enter image description here

1 Answers
Related