Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Edited Issue: Bsonformatter throws an error when passing simple types as ObjectContent [1457]

$
0
0
Server side code
public class MyController : ApiController
{
[AcceptVerbs("PUT", "POST", "DELETE")]
public object EchoDBNullFromBody(object input)
{
return input;
}
}

On the client, if I use ObjectContent<object> I see an error( error and stack trace pasted at the end). I am seeing error with simple types(tried string and int). If I use a customer object then it works fine.

HttpContent content = new ObjectContent<object>("Mystr", new BsonMediaTypeFormatter());
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;

Instead if I use this below, it works fine.
HttpContent content = new ObjectContent(typeof(string),"Mystr", new BsonMediaTypeFormatter());

Error: {"Error writing String value. BSON must start with an Object or Array. Path ''."}

Stack Trace: at Newtonsoft.Json.Bson.BsonWriter.AddToken(BsonToken token)
at Newtonsoft.Json.Bson.BsonWriter.WriteValue(String value)
at Newtonsoft.Json.JsonWriter.WriteValue(Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializePrimitive(JsonWriter writer, Object value, JsonPrimitiveContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value)
at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value)
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding) in c:\dd\AspNET\src\System.Net.Http.Formatting\Formatting\BaseJsonMediaTypeFormatter.cs:line 436
at System.Net.Http.Formatting.BsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>