Maybe this is a stupid issue or question, but I'm facing it since this morning. I am writing a windows service in C#. In the timer-elapsed event handler I make a request to a Web API that returns me a Json, like this:
void OnTimerElapsed(object sender, ElapsedEventArgs e)
{
List<Anomalia> anomalie = null;
TimeIntervalConfigurationModel timeConf = new XmlConfigurationReader.XmlConfigurationHelper().GetTimeIntervalConfiguration();
if (CanNotify(timeConf))
{
try
{
//ricerca anomalie
eventLog.WriteEntry("Contact service: ricerca anomalie....");
WebRequest requestUrl = WebRequest.Create(urlConfig.BaseUrl + urlConfig.Anomalia);
Stream objStream = requestUrl.GetResponse().GetResponseStream();
StreamReader objReader = new StreamReader(objStream);
String sLine = "";
sLine = objReader.ReadToEnd();
anomalie = JsonConvert.DeserializeObject<List<Anomalia>>(sLine);
//cut
}
catch (Exception ex)
{
//cut
}
}
}
Now I am facing a very strange behavior: if I keep the JsonConvert.DeserializeObject>(sLine); instruction the handler method does not execute, if I remove it the methods fires normally. This issue is not due to data format: if I try to deserialize an empty string, or an empty json array, the method does not execute.