From cf7a83e91ce37b38fb22bdec3413bc3cd6bae1c6 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Thu, 8 May 2014 14:33:28 +1200 Subject: [PATCH] -Fixed creator parameters relying on dictionary implementation for order --- .../Serialization/DefaultSerializationBinder.cs | 2 +- .../Serialization/JsonSerializerInternalReader.cs | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Src/Newtonsoft.Json/Serialization/DefaultSerializationBinder.cs b/Src/Newtonsoft.Json/Serialization/DefaultSerializationBinder.cs index aa9ad70a..4b6852b7 100644 --- a/Src/Newtonsoft.Json/Serialization/DefaultSerializationBinder.cs +++ b/Src/Newtonsoft.Json/Serialization/DefaultSerializationBinder.cs @@ -56,7 +56,7 @@ namespace Newtonsoft.Json.Serialization assembly = Assembly.LoadWithPartialName(assemblyName); #pragma warning restore 618,612 #elif NETFX_CORE || PORTABLE - assembly = Assembly.Load(new AssemblyName(assemblyName)); + assembly = Assembly.Load(new AssemblyName(assemblyName)); #else assembly = Assembly.Load(assemblyName); #endif diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs index d8b16ee3..ca275474 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs @@ -1588,16 +1588,21 @@ To fix this error either change the environment to be fully trusted, change the IDictionary extensionData; IDictionary propertyValues = ResolvePropertyAndCreatorValues(contract, containerProperty, reader, objectType, out extensionData); - IDictionary creatorParameters = contract.CreatorParameters.ToDictionary(p => p, p => (object)null); + object[] creatorParameterValues = new object[contract.CreatorParameters.Count]; IDictionary remainingPropertyValues = new Dictionary(); foreach (KeyValuePair propertyValue in propertyValues) { - JsonProperty matchingCreatorParameter = creatorParameters.ForgivingCaseSensitiveFind(kv => kv.Key.PropertyName, propertyValue.Key.PropertyName).Key; + JsonProperty matchingCreatorParameter = contract.CreatorParameters.ForgivingCaseSensitiveFind(p => p.PropertyName, propertyValue.Key.PropertyName); if (matchingCreatorParameter != null) - creatorParameters[matchingCreatorParameter] = propertyValue.Value; + { + int i = contract.CreatorParameters.IndexOf(matchingCreatorParameter); + creatorParameterValues[i] = propertyValue.Value; + } else + { remainingPropertyValues.Add(propertyValue); + } if (propertiesPresence != null) { @@ -1608,7 +1613,7 @@ To fix this error either change the environment to be fully trusted, change the } } - object createdObject = creator(creatorParameters.Values.ToArray()); + object createdObject = creator(creatorParameterValues); if (id != null) AddReference(reader, id, createdObject);