None
None

Reputation: 5670

Error: method deserialize has 1 parameter but invoked with 2 arguments

My code is like this

    using System;
using System.IO;
using System.Web;
using System.Web.Script.Serialization;

public class SaveData : IHttpHandler
{
    public bool IsReusable
    {
        get { return true; }
    }

    public void ProcessRequest(HttpContext context)
    {
        string jsonString = String.Empty;

        context.Request.InputStream.Position = 0;
        using (var inputStream = new StreamReader(context.Request.InputStream))
        {
            jsonString = inputStream.ReadToEnd();
        }

        var javaScriptSerializer = new JavaScriptSerializer();
        object serJsonDetails = javaScriptSerializer.Deserialize(jsonString, typeof (object));

        // You can now add logic to work with serJsonDetails object
    }
}

Everything looks okay to me, I have no Idea why this throws this error

Error: method deserialize has 1 parameter but invoked with 2 arguments 

enter image description here

Upvotes: 0

Views: 1059

Answers (2)

jd6
jd6

Reputation: 429

The message is very clear : the Deserialize method has only one parameter (http://msdn.microsoft.com/fr-fr/library/bb355316(v=vs.110).aspx). But, you are calling the method with two parameters.

If you want to resolve this error, change :

object serJsonDetails = javaScriptSerializer.Deserialize(jsonString, typeof (object));

to :

object serJsonDetails = javaScriptSerializer.Deserialize(jsonString);

EDIT : Which version of .NET Framework did you use ? (the method with 2 arguments was appeared in .NET Framework 4 http://msdn.microsoft.com/fr-fr/library/ee191864(v=vs.110).aspx).

Upvotes: 1

ShayD
ShayD

Reputation: 930

try:

   object serJsonDetails = javaScriptSerializer.Deserialize(jsonString);

Upvotes: 0

Related Questions