The code below fails in deserialization with the following error.
Error converting value "AQID" to type 'System.Collections.Generic.IEnumerable`1[System.Byte]'
public class ByteArrayTest
{
public string SomeString { get; set; }
public IEnumerable<byte> ByteArray { get; set; }
}
using Newtonsoft.Json;
[TestClass]
public class UnitTest10
{
[TestMethod]
public void TestTheByteArraySerialization()
{
var test = new ByteArrayTest { ByteArray = new byte[] { 1, 2, 3 }, SomeString = "testing" };
var serializedData = JsonConvert.SerializeObject(test);
//This line belows fails with an error of can't convert to IEnumerable<byte>
var myByeArrayClass = JsonConvert.DeserializeObject<ByteArrayTest>(serializedData);
Assert.AreEqual(test.ByteArray, myByeArrayClass.ByteArray);
}
}
In my particular case I don't own the ByteArrayTest class, this is just a quick example of the issue. I'd like a solution that doesn't involve modifying the ByteArrayTest class. Ideally I'd pass something into one of the DeserializeObject<> overloads to get this to work, but I'm unsure of the best approach to resolve this exception