RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.4k stars 535 forks source link

The JsonProperty("<name>") attribute is not used when invoked in MS Unit Test v2 project #1138

Open markus-ja opened 4 years ago

markus-ja commented 4 years ago

Hello,

when using Newtonsoft.Json v10 or higher, the NJsonSchema.FromType<> doesn't take the json property name from the attribute. This happens only when code is invoked from the MS Unit Test project (.NetFramework).

class Person { [JsonProperty("first_name")] public string FirstName { get; set; } }

JsonSchema schema = JsonSchema.FromType<Person>(); var actual = schema.ToJson();

JsonConvert.DeserializeObject<Person>(jsonData) ...is wokring as expected.

RicoSuter commented 4 years ago

Have you tried to directly reference the (latest) newtonsoft version in the test project?

markus-ja commented 4 years ago

Yes, I tried the latest newtonsoft version. Interestingly, the DataContract and DataMember attributes are working fine. Its just he JsonProperty, which is not working (only in MS Unit Test project). Using Newtonsoft.Json directly to deserialize or serialize an object, this is also working.

RicoSuter commented 4 years ago

I think i saw this problem a long time ago - something with wrong binging redirects, ie GetCustomAttributes() doesnt return any even if there are some (assembly version mismatch).

sherazlodhi commented 3 years ago

@RicoSuter @markledwich2 is there any workaround for this issue?