I am posting a JSON object from my MonoTouch application to my Asp.MVC Controller. The JSON object has a few string parameters. One of the parameters has a base64 encoded string. The base64 string is a representation of an image.
Issue is: On the server, when the request comes in, sometimes I get this error:
Unterminated string passed in. (49152).
What's worse is that this only happens on production, not dev.
Now, the number 49152, varies from request. My guess is that the JSON string is not getting fully posted. It's being cut off. I've tried using Fiddler to slow down my bandwidth, in case slow internet would be the cause. However, that was not the cause either because i couldn't reproduce the issue on dev with that.
Possible issues, I see:
"\0" getting appended at the end of the Base64 string, as noted here: https://stackoverflow.com/a/710882/487940.I really don't think anything is wrong with the Base64 because the data is getting serialized in the MonoTouch client, so if anything was wrong, then it wouldn't serialized in the first place.- MonoTouch HttpWebRequest not posting all the data. This is likely the issue IMO. The request being sent is gone bad.
Full Stack Trace:
System.ArgumentException: Unterminated string passed in. (49152):
.....LONG JSON STRING WHICH IS MISSING THE END **" }** and possible other characters.
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeString()
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth)
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)
at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)
at System.Web.Mvc.JsonValueProviderFactory.GetValueProvider(ControllerContext controllerContext)
at System.Web.Mvc.ValueProviderFactoryCollection.<>c__DisplayClassc.<GetValueProvider>b__7(ValueProviderFactory factory)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at System.Web.Mvc.ValueProviderFactoryCollection.GetValueProvider(ControllerContext controllerContext)
at System.Web.Mvc.ControllerBase.get_ValueProvider()
at System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor)
at System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
UPDATE
I was thinking that I would intercept the request in asp.net mvc before it gets routed to the controller. If I can intercept it, I can get the raw data and log it. Is there anyway to do this in Asp.Net MVC? As I pointed out above, I really don't think anything is wrong with the Base64 string. It has to be something with the request.