Should IEnumerable.Count Before a "foreach" Enumeration Cause a Single Enumeration Error

  • Thread starter Thread starter AlaskanRogue
  • Start date Start date
A

AlaskanRogue

Guest
Wanting a count of the returned data elements of a data query, I attempted to add the Count method in the code section below, but when reaching the foreach iteration encountered the error “Only a single enumeration is supported by this IEnumerable.” Without the Count code section, the foreach functions properly.

try
{
if (deviceToken != null)
{
Devices_context = result.AsyncState as IdentitiesModel.IdentityServices;
response = Devices_context.EndExecute<IdentitiesModel.Device>(result);
}
else
{
DataServiceQuery<IdentitiesModel.Device> query = result.AsyncState as DataServiceQuery<IdentitiesModel.Device>;
response = query.EndExecute(result);
}

if (response.Count<IdentitiesModel.Device>() == 0)
{
App.verifierID = " ";
App.PCL.MainPage = new NavigationPage(new BadVerifierIDEntry(App.RequestSource + 2));
}

foreach (IdentitiesModel.Device device in response)
{
if (device.ICID == App.ReqICID)
{
activeURI = device.URI;
SendVerificationNotice();
}
}
}

Continue reading...
 
Back
Top