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

Last Reply 5 months ago By dharmendr

Posted 5 months 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.

You are viewing reply posted by: dharmendr 5 months ago.
Posted 5 months 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.
    }
}