quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

Visual Studio having problems referencing the internal class Converter

Open kae36 opened this issue 8 years ago • 3 comments

I was trying to use the QuickType converter to create C# JSON objects to add to my Visual Studio 2017 project and I'm not sure if the generated code should be fully "drop in" or if I need to hook it together. This is what I'm getting.

After using QuickType to convert some JSON objects, the resultant C# code uses the internal class Converter, but Visual Studio 2017 complains that the generated Converter method cannot be resolved in the generated classes.

The Converter class is defined as an internal class to the namespace.

internal class Converter : JsonConverter {

the partial class "Disclosure" defines a static FromJson method that returns the object where the bold method marks the unresolved code.

public partial class Disclosure {
        public static Disclosure FromJson(string json) => JsonConvert.DeserializeObject<Disclosure>(json, Disclosure.**Converter**.Settings);
}

the static Serialize class defines a ToJson method that references the undefined Converter method.

public static class Serialize {
        public static string ToJson(this Disclosure self) => JsonConvert.SerializeObject(self, Disclosure.**Converter**.Settings);
}

I'll add the generated file so you can have at least a picture of the generated code.

Disclosure.zip

kae36 avatar Mar 21 '18 18:03 kae36

It seems that you manually changed the name of the namespace, but you didn't change it where Settings is referenced. You can tell quicktype to use a specific namespace name. Please use that option and you shouldn't get the error.

schani avatar Mar 21 '18 20:03 schani

You can also use refactoring tools (or find and replace) to do an exhaustive manual rename within VS.

dvdsgl avatar Mar 21 '18 20:03 dvdsgl

Sorry about that. That was a big "oh, duh" moment on my part. I even have resharper installed.

kae36 avatar Mar 26 '18 13:03 kae36