Web Service Error: You must implement a default accessor on Newtonsoft.Json.Linq.JObject because it inherits from ICollection

Last Reply 16 days ago By dharmendr

Posted 17 days ago

Using Visual Studio 2010 , FrameWork 3.5, Application WebService.

 below is the code in web service :  

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void StartActivity(JObject objData)
{

}

I am getting error just by declaring jobject as parameter (at run time) as function is void we can avoid implementation.

Although no error if method is not a web method.

No error in compile time, but when I run this code I got below error : 

You must implement a default accessor on Newtonsoft.Json.Linq.JObject because it inherits from ICollection.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: You must implement a default accessor on Newtonsoft.Json.Linq.JObject because it inherits from ICollection.

Posted 16 days ago

Hi Amit,

Instead of passing JObject as parameter, pass a object type as parameter and then convert it back to JObject to do your rest task.

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void StartActivity(object objData)
{
    if (objData.GetType() == typeof(JObject))
    {
        JObject obj = (JObject)objData;
        // Do your Task.
    }
}