Trying to get data from service and bind it to grid
I'm getting the data in localitem and the error occurs on the "foreach" line
any help would be appreciated
private IEnumerable<PersonalIDCheckerMvCKendo.Models.PersonInfo> Getlocalinfo(string personalNO)
{
needsUpdate = false;
using (PersonalInfoServiceClient serviceclient = new PersonalInfoServiceClient())
{
List<PersonalIDCheckerMvCKendo.Models.PersonInfo> personInfo = new List<PersonalIDCheckerMvCKendo.Models.PersonInfo>();
try
{
IEnumerable localItem = serviceclient.GetLocalInfoForPerson(personalNO);
if (localItem != null)
{
foreach (PersonalIDCheckerMvCKendo.Models.PersonInfo dalitem in localItem)
{
personInfo.Add(new PersonalIDCheckerMvCKendo.Models.PersonInfo
{
DocumentSerie = dalitem.DocumentSerie,
DocumentNumber = dalitem.DocumentNumber,
DocumentType = dalitem.DocumentType,
DocumentIssuer = dalitem.DocumentIssuer,
DocumentValidDate = dalitem.DocumentValidDate
});
}
}
return personInfo.ToArray();
}
catch
{
throw;
}
finally
{
serviceclient.Close();
}
}
}
EDIT:
GetLocalInfoForPerson is of type PersonalInformation
public partial class PersonalInformation : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged , System.Collections.IEnumerable
What concrete type does
GetLocalInfoForPersonreturn ? Does it implementIEnumerableproperly ?Based on your code sample, it is hard to say what might be wrong since we don't know the types involved. However, you type the
localItemasIEnumerable, and if this is a custom implementation, someone might have forgotten to implement the non-genericGetEnumeratormethod.Do you get an error if you change the declaration of
localItemto be:?
This would imply that
IEnumerable.GetEnumeratoris not implemented (ie. throws NotImplementedException), whileIEnumerable<T>.GetEnumeratoris in fact implemented. It could also be that both methods are not implemented. Look it up in the code for the type that is returned fromGetLocalInfoForPerson.