6

ASP.NET MVC 4.0 WebAPI (ベータ版) で、65kb を超える JSON にシリアル化されたオブジェクトを返しています。以下のスタック トレースからわかるように、これが何らかの内部制限を超えているため、フレームワークは例外をスローしています。

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()

このデフォルトを変更する方法が見つかりません。誰でも助けることができますか?

ありがとう

4

1 に答える 1

3

ナイトリー ソース コード ビルドでリリースされた System.Net.Http.dll によると、最大バッファ サイズの値は HttpContent で次のように定義されています。

internal const long MaxBufferSize = 0x7fffffffL; // 2147483647

したがって、(ベータ インストーラではなく) 新しいバージョンに切り替えると、問題は解決するはずです。

とにかく、この問題に関係なく切り替えることをお勧めします。かなりの数の重大な変更があり、現在ビルドしているものは最終リリースでは動作しないことが保証されているためです。

于 2012-05-03T19:07:21.317 に答える