Alexandru Antochi
Alexandru Antochi

Reputation: 1465

Cannot apply attribute class 'JsonConverter' because it is abstract

I'm using Newtonsoft JSON library and I'm trying to deserialize a JSON. The problem is that when I use [JsonConverter(typeof(StringEnumConverter))] I get this error: Cannot apply attribute class 'JsonConverter' because it is abstract.

Here are my classes:

 public class ActionRepository
{
    [JsonConverter(typeof(StringEnumConverter))]
    public enum AllowedActions
    {
        FINDWINDOW,
    }

    public enum AllowedParameters
    {
        WINDOWNAME,
    }
}



public class Action
{
    public AllowedActions Name { get; set; }
    public List<Parameter> Parameters { get; set; }
}

I get the squiggly line under the JsonConverter.

EDIT: The JsonConverter class is indeed abstract if I navigate to the class (ctrl+click in VS). I'm using .NET for Windows Universal.

Upvotes: 5

Views: 1845

Answers (1)

TomSelleck
TomSelleck

Reputation: 6968

The problem appears to be that when not targeting a .Net framework application - the JsonConverter class is marked as abstract.

The solution looks to be to use JsonConvert as an alternative.

Upvotes: 2

Related Questions