I need to sort a list of items (IEnumerable ). After sorting with Linq it does not allow me to scan the elements with the foreach.
The code is the following :
const string VERIFICATION_CODE = "where doc.deviceId = \"{0}\" and doc.params =\"\"";
var content = string.Format(VERIFICATION_CODE, dto.DeviceIdorId);
var items = await
DocumentDBRepository<CosmosDBEvents>.GetItemsAsync(content);
if (items == null || items.Count() == 0)
{
return null;
}
items = from item in items
orderby item.descrizione_evento.Severity ascending,item.ts descending
select item;
MessagesController messageController = new MessagesController(_context);
EventsTypeDescriptionsController eventController = new EventsTypeDescriptionsController(_context);
int codice_evento;
string cultura;
foreach (var item in items)
{
codice_evento = Convert.ToInt32(item.eventId);
cultura = GetCulture();
item.decodifica_evento = messageController.GetMessageWithCulture(codice_evento, cultura);
ParserDescrizione(item);
item.descrizione_evento = eventController.GetDetail(codice_evento);
}
return items;
When I try to execute the foreach I get the following error :
"Object reference not set to an instance of an object."
but the collection seems populated if I do a quickwatch.
Can someone help me please.