Click here to Skip to main content
16,021,115 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Unable to cast the object of Type 'System.collections.generic.Keyvaluepair'[string,string] into type of 'System.IConvertible'

here is my code:-------------------------------------------------------------------
C#
private void LoadUniversity()
{
    try
    {
        ObjUtility = new Utility();
        
        cmbUniversity.DataSource = ObjUtility.BindUniversity(StaticInfo.Center_Code).ToList();
          /* error is after this line (May be in BindUniversity method ) */
        
        cmbUniversity.DisplayMember = "Value";
        cmbUniversity.ValueMember = "Key";
        cmbUniversity.SelectedIndex = -1;
        cmbUniversity.Text = "--Select University--";
        ObjUtility = null;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}


//////////here is code of BindUniversity() method//////////
C#
public Dictionary<string, string> BindUniversity(string CenterCode)
{
    ObjUniversityInfoModel = new UniversityInfoModel();
    ObjUniversityInfoModel.CenterCode = CenterCode;
    ObjUniversityInfoServiceClient = new UniversityInfoServiceClient();
    ObjUniversityInfoModelRecordList = new List<UniversityInfoModel>();
    ObjUniversityInfoModelRecordList = ObjUniversityInfoServiceClient.GetUniversityInfoRecordList(ObjUniversityInfoModel);

    if (ObjUniversityInfoModelRecordList[0].Message == "Success" 
            && ObjUniversityInfoModelRecordList[0].Status == true)
    {
        var Result = from s in ObjUniversityInfoModelRecordList
        orderby s.UniversityID descending
        select new
        {
            s.UniversityID,
            s.UniversityName
        };
        ObjDictionary = new Dictionary<string, string>();
        foreach (var Item in Result)
        {
            string U_ID = Item.UniversityID.ToString();
            string U_Name = Item.UniversityName.ToString();
            ObjDictionary.Add(U_ID, U_Name);
        }
    }
    return ObjDictionary;
}

Help me please......
Posted
Updated 28-Nov-14 22:24pm
v3
Comments
BillWoodruff 29-Nov-14 1:33am    
What are 'ObjUtility, and 'Utility ? What Types; how are they structured.
Shubh_0009 29-Nov-14 6:18am    
George Jonsson I have already done all things ..... debugging n all,,,, but no benefit
it is again showing error after this line

cmbUniversity.DataSource = ObjUtility.BindUniversity(StaticInfo.Center_Code).ToList();

1 solution

If you check the stack trace of the exception you get it will pinpoint the exact row where the error occurred.

You could also set a breakpoint on this line:
C#
cmbUniversity.DataSource = ObjUtility.BindUniversity(StaticInfo.Center_Code).ToList();

Then use the Step Into (F11) function in the debugger to enter the method BindUniversity.
Then use Step Over (F10) and debug the method line by line.

By doing this you can most likely find and correct the error yourself.
 
Share this answer
 

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