Deserialization issue with Dictionary cannot resolve type using JsonFx for Unity

This was working but appears broken in latest build. Perhaps an issue with changes around the windows phone.

Hoping you can help. Switching over to arrays works ie TestObj[]

`using UnityEngine;
using System.Collections.Generic;

public class Test : MonoBehaviour {

// Use this for initialization
void Start () 
{
	Dictionary<string, TestObj> my = new Dictionary<string, TestObj>();
	my.Add("1", new TestObj(){ id = "1" });
	my.Add("2", new TestObj(){ id = "2" });
	my.Add("3", new TestObj(){ id = "3" });
			
	var sMy = JsonWriter.Serialize(my);
	
	var final = JsonReader.Deserialize<Dictionary<string, TestObj>>(sMy);
}

// Update is called once per frame
void Update () {

}

}

public class TestObj
{
public string id;
}`

Actually this only appears to be an issue if I compile the dll externally and drop it into unity. Placing the source directly into unity works fine. Not sure why.

Have you modified the JsonFx dll somehow? I see you are not “using Pathfinding.Serialization.JsonFx”.

I had but just reverted back to original code. So the issue appears to be that if I compile with the compiler directive WIN_PHONE8 as per your default settings you cannot deserialize generic dictionaries per this code in the following methods

That directive appears to basically kill the Dictionary<string, object> functionality and throw an error where it has no idea what the type is to deserialize. I removed the WINPHONE_8 directive from Mono and rebuilt and then it works. Unfortunately I am guessing (need to try this) that I will no longer be able to build windows 8 phone apps because of incompatibility with TypeGenericIDictionary (or something else in this code).

So am I correct in assuming that JsonFx right now for windows 8 phone cannot support generic dictionaries? Thanks.

private Type GetGenericDictionaryType (Type objectType) {
// this allows specific IDictionary<string, T> to deserialize T
#if !WINPHONE_8
Type genericDictionary = objectType.GetInterface(JsonReader.TypeGenericIDictionary);
if (genericDictionary != null)
{
Type[] genericArgs = genericDictionary.GetGenericArguments();
if (genericArgs.Length == 2)
{
if (genericArgs[0] != typeof(String))
{
throw new JsonDeserializationException(
String.Format(JsonReader.ErrorGenericIDictionaryKeys, objectType),
this.index);
}

				if (genericArgs[1] != typeof(Object))
				{
					return genericArgs[1];
				}
			}
		}

#endif
return null;
}

	private void PopulateObject (ref object result, Type objectType, Dictionary<string, MemberInfo> memberMap, Type genericDictionaryType)
	{
		if (this.Source[this.index] != JsonReader.OperatorObjectStart)
		{
			throw new JsonDeserializationException(JsonReader.ErrorExpectedObject, this.index);
		}

#if WINPHONE_8
IDictionary idict = result as IDictionary;
#else
IDictionary idict = result as IDictionary;

		if (idict == null && objectType.GetInterface(JsonReader.TypeGenericIDictionary) != null )
		{
			throw new JsonDeserializationException(
				String.Format(JsonReader.ErrorGenericIDictionary, objectType),
				this.index);
		}

#endif

BTW serialization works just not deserialization.

Oh and thanks for the help.