Thursday, April 23, 2015

Json Deserialization not working after app publish in store

Hi,

I have a very annoying problem with my app. I'm using Json.net to deserialize json content. When I'm testing my app on emulator or device connected through Visual Studio everything works fine and data is deserializing. But after I build package to publish in the store the deserialization is not working and I'm catching NullReferenceException in line:

return (TItem)serializer.Deserialize(streamReader, typeof(TItem));

of code:

protected TItem DeserializeJson<TItem>(String json)
        {
            if (json != null)
            {
                try
                {
                    using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
                    {
                        JsonSerializer serializer = new JsonSerializer();
                        using (StreamReader streamReader = new StreamReader(ms))
                        {
                            return (TItem)serializer.Deserialize(streamReader, typeof(TItem));
                        }
                    }
                }
                catch (Exception ex)
                {
                    App.TelemetryClient.TrackException(ex);
                }
            }

            return default(TItem);
        }

I was also using DataContractJsonSerializer with the same exception...

It's very strange because when I prepare package with the No answer on the first page of Create App Packages and then I deploy this package on my phone through Window Phone Application Deployment the data deserialization is working perfectly.

I really don't have any idea why it's not working... It really drives me crazy :/

Maybe someone from Microsoft could help me with that problem?

I'm using Visual Studio 2013 Update 4. My app is built as a Windows Phone 8.1 app.

Artur

No comments:

Post a Comment