ArgumentException:传入未终止的字符串

时间:2012-11-22 09:20:02

标签: asp.net

我最近在我网站的某个页面中遇到此错误。

[ArgumentException: Unterminated string passed in. (26): {"selectedIndexes":["0"],"]
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeString()
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeMemberName()
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.Script.Serialization.JavaScriptSerializer.DeserializeObject(String\ input)
at Telerik.Web.UI.RadCompositeDataBoundControl.LoadPostData(String postDataKey,\ NameValueCollection postCollection)
at Telerik.Web.UI.RadCompositeDataBoundControl.System.Web.UI.IPostBackDataHandler.LoadPostData(String\ postDataKey, NameValueCollection postCollection)
at System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean\ fBeforeLoad)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,\ Boolean includeStagesAfterAsyncPoint)

[HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown.]
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,\ Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint,\ Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.pages_appeal_appealaction_aspx.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

这种例外的原因是什么?任何想法如何解决?

1 个答案:

答案 0 :(得分:0)

是的。当ASP.NET系统收到请求,将其路由到您的处理程序并且ModelBinder接管传递给处理程序中的参数的映射值时,会发生此错误。当其中一个parms是一个字符串并且该字符串已启动但未终止时,它将从System.String.DeserializeString()方法抛出System.ArgumentException。

您有两种选择。

  1. 在发送之前,使用JavaScript在浏览器中修复字符串数据。 (杜)。
  2. 创建自定义Model Binder以优雅地处理异常并发回500系列HTTP错误或更好,然后以可预测的方式修复数据。这种修复并不总是像声音文件,图像,电影或其他base64编码的blob一样。
  3. 以下是#2 - Creating a custom model binder的方法。