diff --git a/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs
index fd3c1f8e..02ac0a48 100644
--- a/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs
@@ -8,6 +8,7 @@ using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.Formatters;
using System.Text;
+using Newtonsoft.Json.Tests.TestObjects;
using Newtonsoft.Json.Utilities;
using NUnit.Framework;
diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs
index 38c85ba3..e2502b66 100644
--- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs
+++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs
@@ -4154,5 +4154,29 @@ keyword such as type of business.""
Assert.AreEqual("Two", c2.Enumerable.ElementAt(1));
Assert.AreEqual("Three", c2.Enumerable.ElementAt(2));
}
+
+ [JsonObject(MemberSerialization.OptIn)]
+ public class ItemBase
+ {
+ [JsonProperty]
+ public string Name { get; set; }
+ }
+
+ public class ComplexItem : ItemBase
+ {
+ public Stream Source { get; set; }
+ }
+
+ [Test]
+ public void SerializeAttributesOnBase()
+ {
+ ComplexItem i = new ComplexItem();
+
+ string json = JsonConvert.SerializeObject(i, Formatting.Indented);
+
+ Assert.AreEqual(@"{
+ ""Name"": null
+}", json);
+ }
}
}
\ No newline at end of file
diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs
index 7da76786..9f89a624 100644
--- a/Src/Newtonsoft.Json/Linq/JValue.cs
+++ b/Src/Newtonsoft.Json/Linq/JValue.cs
@@ -167,20 +167,20 @@ namespace Newtonsoft.Json.Linq
case JTokenType.Comment:
case JTokenType.String:
case JTokenType.Raw:
- string s1 = Convert.ToString(objA);
- string s2 = Convert.ToString(objB);
+ string s1 = Convert.ToString(objA, CultureInfo.InvariantCulture);
+ string s2 = Convert.ToString(objB, CultureInfo.InvariantCulture);
return s1.CompareTo(s2);
case JTokenType.Boolean:
- bool b1 = Convert.ToBoolean(objA);
- bool b2 = Convert.ToBoolean(objB);
+ bool b1 = Convert.ToBoolean(objA, CultureInfo.InvariantCulture);
+ bool b2 = Convert.ToBoolean(objB, CultureInfo.InvariantCulture);
return b1.CompareTo(b2);
case JTokenType.Date:
if (objA is DateTime)
{
- DateTime date1 = Convert.ToDateTime(objA);
- DateTime date2 = Convert.ToDateTime(objB);
+ DateTime date1 = Convert.ToDateTime(objA, CultureInfo.InvariantCulture);
+ DateTime date2 = Convert.ToDateTime(objB, CultureInfo.InvariantCulture);
return date1.CompareTo(date2);
}
@@ -555,12 +555,30 @@ namespace Newtonsoft.Json.Linq
return Compare(_valueType, _value, otherValue);
}
- public int CompareTo(JValue other)
+ ///
+ /// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
+ ///
+ /// An object to compare with this instance.
+ ///
+ /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:
+ /// Value
+ /// Meaning
+ /// Less than zero
+ /// This instance is less than .
+ /// Zero
+ /// This instance is equal to .
+ /// Greater than zero
+ /// This instance is greater than .
+ ///
+ ///
+ /// is not the same type as this instance.
+ ///
+ public int CompareTo(JValue obj)
{
- if (other == null)
+ if (obj == null)
return 1;
- return Compare(_valueType, _value, other._value);
+ return Compare(_valueType, _value, obj._value);
}
}
}
\ No newline at end of file
diff --git a/Src/Newtonsoft.Json/Utilities/DynamicWrapper.cs b/Src/Newtonsoft.Json/Utilities/DynamicWrapper.cs
index 8e888190..0df9f4ac 100644
--- a/Src/Newtonsoft.Json/Utilities/DynamicWrapper.cs
+++ b/Src/Newtonsoft.Json/Utilities/DynamicWrapper.cs
@@ -79,8 +79,16 @@ namespace Newtonsoft.Json.Utilities
if (wrapperType == null)
{
- wrapperType = GenerateWrapperType(interfaceType, realObjectType);
- _wrapperDictionary.SetType(interfaceType, realObjectType, wrapperType);
+ lock (_lock)
+ {
+ wrapperType = _wrapperDictionary.GetType(interfaceType, realObjectType);
+
+ if (wrapperType == null)
+ {
+ wrapperType = GenerateWrapperType(interfaceType, realObjectType);
+ _wrapperDictionary.SetType(interfaceType, realObjectType, wrapperType);
+ }
+ }
}
return wrapperType;