title: WEB API Sequence contains no elements
body: <p>I have created a <code>WEB API</code> which is working on my local system. But after deploying it on the server it gives me bellow error/exception. </p>
  
  <blockquote>
    <p>{"Message":"An error has occurred.","ExceptionMessage":"Sequence
    contains no
    elements","ExceptionType":"System.InvalidOperationException","StackTrace":"
    at System.Linq.Enumerable.First[TSource](IEnumerable<code>1 source)\r\n at
    System.Linq.Queryable.First[TSource](IQueryable</code>1 source)\r\n at
    ActualWebService.Controllers.MetersController.GetByMsn(String msn,
    DateTime dt)"}</p>
  </blockquote>
  
  <p><strong>I am checking it on postman in server and also in my local system</strong></p>
  
  <p>Below is my code</p>
  
  <pre><code> public HttpResponseMessage GetByMsn(string msn, DateTime dt)
      {          
          try
          {
  
              var result = medEntitites.tj_xhqd.Where(m =&gt; m.zdjh == msn)
                                               .OrderByDescending(o =&gt; o.sjsj)
                                               .Select(s =&gt; s.sjsj)
                                               .First();
  
              DateTime resulted = new DateTime();
              DateTime userSent = new DateTime();
  
              resulted = Convert.ToDateTime(result);
              userSent = Convert.ToDateTime(dt);
  
  
              double diff = Math.Abs((resulted - userSent).TotalMinutes); // here i am checking the difference between the user sent datetime and resulted date time
  
              if (diff &lt;=10)
              {
                  return Request.CreateResponse(HttpStatusCode.OK, new { data = new { Response = "Yes"} });
              }
              else
              {
                  return Request.CreateResponse(HttpStatusCode.OK, new { data = new { Response = "No" } });
              }
  
          }
          catch (Exception ex)
          {
              return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
          }
      }
  </code></pre>
  
  <p><strong>WebApiConfig</strong></p>
  
  <pre><code> config.Routes.MapHttpRoute(
         name: "GetByMsn",
         routeTemplate: "api/{controller}/{action}/{msn}/{dt}",
         defaults: null,
         constraints: new { msn = @"^[0-9]+$" , dt = @"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$" }
         );
  </code></pre>
  
  <p><strong>SERVER LOCAL URL:</strong> <code>http://localhost:8080/api/meters/GetByMsn/0002999000536/2017-10-21T18:26:08</code></p>
  
  <p>I don't know why this API is not working <code>LIVE</code> as it's working on local system. It should work on server also.</p>
  
  <p>Any help would be highly appreciated</p>