5

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.

2
  • [JsonConverter(typeof(StringEnumConverter))] doesn't apply an attribute of type JsonConverter, it applies the attribute JsonConverterAttribute which is not abstract. Commented Apr 18, 2019 at 16:43
  • From the c# language spec: Attributes: By convention, attribute classes are named with a suffix of Attribute. An attribute_name of the form type_name may either include or omit this suffix. If an attribute class is found both with and without this suffix, an ambiguity is present, and a compile-time error results. So it's odd that the IDE somehow thought JsonConverter was being applied rather than JsonConverterAttribute. Possibly an IDE bug here? Commented Apr 18, 2019 at 16:43

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Silly idea, but since it's abstract what if you just make your own subclass and use that?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.