I have strange behavior that I cannot understand.
I use the WCF service to save files in a specific DB table. The WCF service has a single method that takes a JSON string as a parameter. JSON in this case is a serialized command that contains List<FileData>among other properties. The WCF service deserializes JSON and launches CommandHandlerfor this particular command.
The end user encountered an error when he tried to download a 52 MB file. WCF service returned error 404.
I was able to reproduce this in Visual Studio. After changing the configuration file in accordance with this article , 404 disappeared.
But now a new exception has appeared: although the command has been successfully serialized on the client side, WCF has successfully processed, deserialization throws OutOfMemoryException. This is the top of stacktrace:
in Newtonsoft.Json.JsonTextReader.ReadData (Boolean append, Int32 charsRequired) in Newtonsoft.Json.JsonTextReader.ReadData (Boolean append) in Newtonsoft.Json.JsonTextReader.ReadStringIntoBuffer (Char quote) in Newtonsoft.Json.JsonTextReader.ParseString (Char quote ) in Newtonsoft.Json.JsonTextReader.ParseValue () in Newtonsoft.Json.JsonTextReader.ReadInternal () in Newtonsoft.Json.JsonReader.ReadAsBytesInternal () in Newtonsoft.Json.JsonTextReader.ReadAsByerial.Json.Json.Json.Jonal.Json.Jones.jsinter ReadForType (JsonReader reader, JsonContract contract, Boolean hasConverter)
unittest, . , , , , OutOfMemoryException.
:
[TestMethod]
public void LoadBigFile_SerializeDeserialize_DoesntThrowOutOfMemoryException()
{
byte[] bytes = new byte[80000000];
Random r = new Random(23);
r.NextBytes(bytes);
var command = new SomeCommand(new List<FileData>
{
new FileData(
fileFullName: @"D:\SomePdfFile.pdf",
modifyDate: DateTime.MaxValue,
data: bytes
)
});
var data = JsonConvert.SerializeObject(command);
var deserializedCommand =
JsonConvert.DeserializeObject<SomeCommand>(data);
Assert.AreEqual(bytes.Length, deserializedCommand.Files.First().Data.Length);
}
, . !!! OutOfMemoryException!
: OutOfMemoryException Visual Studio, unittest VS - ? , Visual Studio, . , Debug, Release.
:
- Json.Net 7.0.1
- Visual Studio 2015, 2
- WCF IIS Express , IIS
- Windows 10 64
- Windows 2008 R2 64
- .Net Framework 4.5.2