-Fixed exceptions not being binary serializable
This commit is contained in:
@@ -34,6 +34,9 @@ using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Schema;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
#if !(NET20 || NET35 || NET40)
|
||||
using System.Threading.Tasks;
|
||||
#endif
|
||||
#if DNXCORE50
|
||||
using Xunit;
|
||||
using Test = Xunit.FactAttribute;
|
||||
@@ -606,6 +609,29 @@ namespace Newtonsoft.Json.Tests
|
||||
Assert.AreEqual(4, value.Count);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !(NET20 || NET35 || NET40 || PORTABLE || DNXCORE50)
|
||||
[Test]
|
||||
public async Task AsyncDemo()
|
||||
{
|
||||
JArray largeJson;
|
||||
|
||||
// read asynchronously from a file
|
||||
using (TextReader textReader = new StreamReader(new FileStream(@"large.json", FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true)))
|
||||
{
|
||||
largeJson = await JArray.LoadAsync(new JsonTextReader(textReader));
|
||||
}
|
||||
|
||||
JToken user = largeJson.SelectToken("$[?(@.name == 'Woodard Caldwell')]");
|
||||
user["isActive"] = false;
|
||||
|
||||
// write asynchronously to a file
|
||||
using (TextWriter textWriter = new StreamWriter(new FileStream(@"large.json", FileMode.Open, FileAccess.Write, FileShare.Write, 4096, true)))
|
||||
{
|
||||
await largeJson.WriteToAsync(new JsonTextWriter(textWriter));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || NET40 || PORTABLE || DNXCORE50)
|
||||
|
||||
@@ -24,6 +24,10 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
#if !(PORTABLE || DNXCORE50)
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
#endif
|
||||
using Newtonsoft.Json.Schema;
|
||||
#if DNXCORE50
|
||||
using Xunit;
|
||||
@@ -100,5 +104,18 @@ namespace Newtonsoft.Json.Tests
|
||||
Assert.AreEqual("Inner!", exception.InnerException.Message);
|
||||
}
|
||||
#pragma warning restore 618
|
||||
|
||||
#if !(PORTABLE || DNXCORE50)
|
||||
[Test]
|
||||
public void BinarySerializeException()
|
||||
{
|
||||
JsonReaderException exception = new JsonReaderException("message!");
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
var binaryFormatter = new BinaryFormatter();
|
||||
binaryFormatter.Serialize(memoryStream, exception);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user