Telerik.Web.UI.RadComboBoxContext is not supported because it implements IDictionary

private const int ItemsPerRequest = 10; [WebMethod] public RadComboBoxItemData[] GetAccount(object context) { RadComboBoxContext obj = (RadComboBoxContext)context; DataTable data = GetDataAccount(obj.Text); RadComboBoxData comboData = new RadComboBoxData(); int itemOffset = obj.NumberOfItems; int endOffset = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count); comboData.EndOfItems = endOffset == data.Rows.Count; List result = new List(endOffset - itemOffset); for (int i = itemOffset; i < endOffset; i++) { RadComboBoxItemData itemData = new RadComboBoxItemData(); itemData.Value = data.Rows[i]["AccountLevelNo"].ToString(); itemData.Text = data.Rows[i]["AccountDesc3"].ToString(); itemData.Attributes.Add("Level6", data.Rows[i]["AccountDesc2"].ToString()); itemData.Attributes.Add("Level1", data.Rows[i]["AccountDesc1"].ToString()); result.Add(itemData); } comboData.Items = result.ToArray(); // comboData.Message = GetStatusMessage(endOffset, data.Rows.Count); return comboData.Items.ToArray(); } private static DataTable GetDataAccount(string text) { int accCode = 0; string query = "select COA.LevelAccountNo,COA.AccountDesc as AccountDesc3,Level1.AccountDesc as AccountDesc1, Level2.AccountDesc as AccountDesc2 from COA COA,(select LevelAccountNo,AccountDesc " + "from COA where len(LevelAccountNo)=2)as Level1,(select LevelAccountNo,AccountDesc from COA where len(LevelAccountNo)=5)as Level2 " + "where Level1.LevelAccountNo=left(COA.LevelAccountNo,2)and Level2.LevelAccountNo=left(COA.LevelAccountNo,5) and len(COA.LevelAccountNo)>6"; try { accCode = Convert.ToInt32(text); query = query + " COA.LevelAccountNo like '" + text + "%'"; } catch (Exception ex) { query = query + " COA.AccountDesc3 like '%" + text + "%'"; } SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"].ToString()); // string constr=ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlDataAdapter adapter = new SqlDataAdapter(query, con); // adapter.SelectCommand.Parameters.AddWithValue("@text", text); DataTable data = new DataTable(); adapter.Fill(data); con.Close(); return data; } 

this is my web service code

  Collapse | Copy Code <telerik:RadComboBox ID="cboAccount" runat="server" Height="200" Width="200" EmptyMessage="Select an Account" EnableLoadOnDemand="true" ShowMoreResultsBox="true" EnableVirtualScrolling="true"> <HeaderTemplate> <h3>Accounts</h3> </HeaderTemplate> <ClientItemTemplate> <div> <ul> <li><span><b>Name:#= Text # </b></span></li> <li><span>Level6 #= Attributes.Level6 # </span></li> <li><span>Level1: #= Attributes.Level4 # </span></li> <li><span>Level4 #= Attributes.Level1 # </span></li> </ul> </div> <br></br> </ClientItemTemplate> <WebServiceSettings Method="GetAccount" Path="InvestmentDropDownWebService.asmx" /> </telerik:RadComboBox> 

This is the first time I'm using webservice in my project. I do not know how to solve this error. If I execute aspx.cs , this works fine, and the values ​​bind to the combo box. But when I bind values ​​to combobox using a web service, it gives an error:

The Telerik.Web.UI.RadComboBoxContext type is not supported because it implements IDictionary.

+6
source share
2 answers

This issue occurs because of the Visual Studio debugger. This is due to its default behavior. There is a workaround. Change your line

 [WebMethod] 

to

 [WebMethod(EnableSession = true)] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] 

Also add attribute

 WebServiceSettings-UseHttpGet="true" 

in your ASPX RadCombo Box code.
See this question in the Telerik forum for more details on this issue.

+2
source

The cause of the problem is serialization (xml). Remember that the serialization mechanism was built at the very beginning of the platform, which was nice because after it shared collections / dictionaries were added. This means that the functionality you expect to work now may not have been possible during the initial development.

This brings us to the dictionary. The dictionary base class does not support serialization, because the serializer does not really like / handle "unknown" types. Since dictionaries can be β€œ[object, object]”, this is an unknown type of sky.

An interesting way to create a similar problem with an unknown type is as follows.

  • Create a web service expecting class 'a' as a parameter.
  • Create a web link to the service.
  • Create a class 'b' that derives from 'a'.
  • Now call the web method with instance 'b' as parameter

You will now receive an error message stating that the call failed because "type b was unexpected." Hope you see how these two things are related (unexpected type / dictionary) ...

You can only provide an XML serializer of the types that it was told to expect during development

The "sohaiby" solution will work because it tells the web service NOT to use xml serialization, but to use JSON in the line:

 ResponseFormat = ResponseFormat.Json 

That’s all said, this is truly a Telerics bug, and they need to fix it.

0
source

Source: https://habr.com/ru/post/955336/


All Articles