Click here to Skip to main content
15,886,780 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have created a asp.net webservice but when i am running the code it is giving me the following error :
Quote:
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.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[InvalidOperationException: You must implement a default accessor on Newtonsoft.Json.Linq.JObject because it inherits from ICollection.]
System.Xml.Serialization.TypeScope.GetDefaultIndexer(Type type, String memberInfo) +5361982
System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type, MemberInfo memberInfo, Boolean directReference) +1475
System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError) +157
System.Xml.Serialization.XmlReflectionImporter.ImportMemberMapping(XmlReflectionMember xmlReflectionMember, String ns, XmlReflectionMember[] xmlReflectionMembers, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +71
System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +300


What I have tried:

I am using VS2017
below is the code that i have created : 
<pre lang="vb">


<blockquote class="quote"><div class="op">Quote:</div>
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Imports System.Net
Imports System.Data.SqlClient
Imports System.IO

<blockquote class="quote"><div class="op">Quote:</div><System.Web.Services.WebService(Namespace:="http://tempuri.org/")>
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
<ToolboxItem(False)>
Public Class CovidWebService</blockquote>
<WebMethod>
    Public Function SubGetVisitorsListNew(ByVal jsonResult As JObject) As String
        Dim mMsg As String = "Done"
        MyConConnection.Open()

        Try

            Dim details = JObject.Parse(jsonResult)

            Dim ser As JObject = JObject.Parse(jsonResult)
            Dim data As List(Of JToken) = ser.Children().ToList
            Dim output As String = ""
            For Each item As JProperty In data
                item.CreateReader()
                Select Case item.Name
                    Case "visitors"
                        For Each msg As JObject In item.Values
                            mCmd = "INSERT INTO SurveyVisitorsData "
                            mCmd = mCmd & " (FamilyHeadSerialNo, Name,Age, AgeDetails, Sex, IfUNRResident) "
                            mCmd = mCmd & " VALUES "
                            mCmd = mCmd & " (@mFamilyHeadSerialNo, @mName,@mAge, @mAgeDetails, @mSex, @mIfUNRResident) "
                            cmd = New SqlCommand(mCmd, MyConConnection)
                            cmd.Parameters.AddWithValue("@mFamilyHeadSerialNo", msg("FamilyHeadSerialNo"))
                            cmd.Parameters.AddWithValue("Name", msg("Name"))
                            cmd.Parameters.AddWithValue("contact_number", msg("contact_number"))
                            cmd.Parameters.AddWithValue("Age", msg("Age"))
                            cmd.Parameters.AddWithValue("AgeDetails", msg("AgeDetails"))
                            cmd.Parameters.AddWithValue("Sex", msg("Sex"))
                            cmd.Parameters.AddWithValue("IfUNRResident", msg("IfUNRResident"))
                            cmd.ExecuteNonQuery()

                        Next
                End Select
            Next
        Catch ex As Exception
            mMsg = ex.Message.ToString
        End Try
        MyConConnection.Close()
        Return mMsg
    End Function

End Class
</blockquote>
Posted
Comments
ZurdoDev 27-Jul-20 13:01pm    
Which line of code causes the error?
Sandeep Mewara 28-Jul-20 1:38am    
Have a read of this and see if this helps: https://weblog.west-wind.com/posts/2012/aug/30/using-jsonnet-for-dynamic-json-parsing

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900