Click here to Skip to main content
15,179,684 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
void loginfn(object sender, loginCompletedEventArgs e)
  {

      if (e.Result!= null)
      {

          List<customer> c = e.Result;//error arises in this line 

          foreach (customer c1 in c)
          {
            Guid  id=c1.companyrefid;
          }
         
      }
      else
      {
          MessageBox.Show("password not correct ");
      }

  }


through wcf i am getting values
public List<customer> login(string salesmanname, string usercode)
Posted
Updated 1-Jun-14 23:01pm
v3
Comments
Karthik_Mahalingam 2-Jun-14 1:24am
   
what is the Type of e.Result ??
Nandhini Devi 2-Jun-14 1:25am
   
it contains list which i got from wcf service
Karthik_Mahalingam 2-Jun-14 1:41am
   
how many items are expected in the list ?
hopefull one ???
Nandhini Devi 2-Jun-14 1:52am
   
2 items i can see items in e.result but not able to assign
Karthik_Mahalingam 2-Jun-14 1:58am
   
make sure that the last item in the list has values, because in the looping, the variable will store only the last item in the collection.
Nandhini Devi 2-Jun-14 2:50am
   
all values are there only but still not able to assign

Try not casting :
C#
foreach (customer c1 in e.Result)
...
   
Comments
Nandhini Devi 2-Jun-14 1:36am
   
i used this method but value is not getting assigned in id and company but i can see value in c1 using breakpoint
foreach (customer c1 in e.Result)
{
Guid companyrefid = c1.companyrefid;
int id = c1.id;
}
1. e.Result must be (OR must contain as cached) an object of type:
C#
List<customer>
OR
C#
List<ParentOfCustomerClass>

2. You should use an explicit cast:
C#
<List<customer> c = (List<customer>)e.Result;
   
v2
Comments
Nandhini Devi 2-Jun-14 1:34am
   
i am getting error like this again "error while converting system.collection.objectmodel.observation to generic list"
Raul Iloc 2-Jun-14 6:25am
   
See my update!
Try this

C#
System.Collections.ObjectModel.ObservableCollection<customer> temp = e.Result;

           foreach (var item in temp)
           {
               Guid companyrefid = item.companyrefid;
               int id = item.id;
           }
   
v2
Comments
Nandhini Devi 2-Jun-14 1:58am
   
no still values not getting assigned in id and companyrefid ... can anyone tell reason why its not getting assigned ?
C#
ObservableCollection<customer> temp = new ObservableCollection<customer>(e.Result);

          foreach (var item in temp)
          {
                  companyrefid= item.companyrefid;
                  int id = item.id;
                  //  MessageBox.Show("id:"+id).ToString();
          }


its working fine now
   
v2
Comments
Karthik_Mahalingam 2-Jun-14 4:11am
   
mark it as answer and close the post.

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