2012-05-03 14 views
6

In WebAI ASP.NET MVC 4.0 (versione beta), restituisco un oggetto serializzato su JSON che è più grande di 65kb. Come puoi vedere dalla traccia dello stack di seguito, il framework lancia un'eccezione perché supera un limite interno.ASP.NET MVC 4 WebAPI (beta) - come modificare la dimensione massima del buffer di risposta

System.Net.Http.HttpRequestException: Cannot write more bytes to the buffer than the configured maximum buffer size: 65536. 
    at System.Net.Http.HttpContent.LimitMemoryStream.CheckSize(Int32 countToAdd) 
    at System.Net.Http.HttpContent.LimitMemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count) 
    at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder) 
    at System.IO.StreamWriter.Write(Char value) 
    at Newtonsoft.Json.JsonWriter.AutoComplete(JsonToken tokenBeingWritten) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonWriter.cs:line 634 
    at Newtonsoft.Json.JsonTextWriter.WritePropertyName(String name) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonTextWriter.cs:line 204 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteMemberInfoProperty(JsonWriter writer, Object memberValue, JsonProperty property, JsonContract contract) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:line 209 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContract collectionValueContract) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:line 336 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteMemberInfoProperty(JsonWriter writer, Object memberValue, JsonProperty property, JsonContract contract) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:line 209 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContract collectionValueContract) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:line 336 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IWrappedCollection values, JsonArrayContract contract, JsonProperty member, JsonContract collectionValueContract) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:line 445 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteMemberInfoProperty(JsonWriter writer, Object memberValue, JsonProperty property, JsonContract contract) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:line 209 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContract collectionValueContract) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:line 336 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteMemberInfoProperty(JsonWriter writer, Object memberValue, JsonProperty property, JsonContract contract) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:line 209 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContract collectionValueContract) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:line 336 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IWrappedCollection values, JsonArrayContract contract, JsonProperty member, JsonContract collectionValueContract) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:line 445 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:line 59 
    at xxx.Api.JsonNetFormatter.<>c__DisplayClass5.<OnWriteToStreamAsync>b__4() in c:\xxx\xxx\xxx.Api\JsonNetFormatter.cs:line 79 
    at System.Threading.Tasks.Task.Execute() 

Non riesco a trovare alcun modo per modificare questo valore predefinito. Qualcuno può aiutare?

grazie

+0

Avete provato questo: http://forums.asp.net/t/1795106.aspx/1?Set+length+of+web+response – syneptody

+0

@syneptody non sto usando il serializzatore json predefinito così I ' Non sono sicuro se questo si applica. grazie per il collegamento comunque, avrà un violino basato sui suoi suggerimenti. – Andrew

+0

Puoi pubblicare le parti rilevanti della tua classe 'JsonNetFormatter'? – nemesv

risposta

3

Secondo la System.Net.Http.dll rilasciato con la fonte nightly build del codice, il valore della dimensione massima del buffer è definito in HttpContent come:

internal const long MaxBufferSize = 0x7fffffffL; // 2147483647 

Quindi, se si passa alla nuova versione (piuttosto che al beta installer) il problema dovrebbe andare via.

suggerisco di passare in ogni caso indipendentemente da questo problema in quanto vi sono un bel po 'di rottura cambia e tutto ciò che si sta costruendo ora è garantito di non lavorare con la versione finale.

+0

grazie - sembra che questo è quello che ho intenzione di fare, ahimè. – Andrew

+0

La commutazione è avvenuta? Sto vedendo questa stessa traccia dello stack ma non sto usando nessuna versione beta, per quanto ne so. – PandaWood

Problemi correlati