title: Object Reference Not Set To An Instance Of An Object: Yelp Return Values
body: <p>I'm making a call to Yelp, to get reviews for some addresses in an apartment finder I've written, but it looks like some of the Yelp data isn't complete, so the following code results in Ye Olde ORNSTAIOAN error:</p>
  
  <pre><code>    public IEnumerable&lt;Review&gt; GetReviews(Bounds searchBounds) {
          var yelp = new Y.Yelp(ConfigOptions);
          var searchOptions = GetSearchOptions(searchBounds);
          var searchTask = yelp.Search(searchOptions);
          var tasks = new Task&lt;Y.Data.SearchResults&gt;[GetTaskArraySize(searchTask)];
  
          tasks[0] = searchTask;
  
          for (var i = 1; i &lt; tasks.Length; i++) {
              searchOptions.GeneralOptions.offset = i * YelpResultsLimit;
              tasks[i] = yelp.Search(searchOptions);
          }
  
          Task.WaitAll(tasks);
  
          return tasks.SelectMany(t =&gt; t.Result.businesses != null
              ? t.Result.businesses
              : null)
                      .Select(MapYelpBusinessToReview);
      }
  </code></pre>
  
  <p>The error hits in the return line, on "businesses", even if I try a null catch, as I am above. The error outputs as:</p>
  
  <pre><code>&lt;Error&gt;
      &lt;script id="tinyhippos-injected"/&gt;
      &lt;Message&gt;
          An error has occurred.
      &lt;/Message&gt;
      &lt;ExceptionMessage&gt;
          Object reference not set to an instance of an object.
      &lt;/ExceptionMessage&gt;
      &lt;ExceptionType&gt;
          System.NullReferenceException
      &lt;/ExceptionType&gt;
      &lt;StackTrace&gt;
          at System.Linq.Enumerable.&lt;SelectManyIterator&gt;d__14`2.MoveNext() at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at ApartmentFinder.Infrastructure.Services.SearchEngine.&lt;&gt;c__DisplayClassc.&lt;FindProperties&gt;b__1() in c:\Development\myProject\ApartmentFinder.Infrastructure\Services\SearchEngine.cs:line 25 at System.Threading.Tasks.Task`1.InnerInvoke() at System.Threading.Tasks.Task.Execute()
      &lt;/StackTrace&gt;
  &lt;/Error&gt;
  </code></pre>
  
  <p>How can I trap the missing business information, and proceed with/without it?</p>
  
  <p>Update:</p>
  
  <p><img src="https://i.stack.imgur.com/JU48L.png" alt="YelpSharp.Data.Business"></p>
  
  <pre><code>namespace ApartmentFinder.Infrastructure.Models {
      /// &lt;summary&gt;
      /// Provides the set of properties describing a review for a property.
      /// &lt;/summary&gt;
      public class Review {
          public string Id{ get; set; }
          public string Name{ get; set; }
          public string Address{ get; set; }
          public string City{ get; set; }
          public string State{ get; set; }
          public string ZipCode{ get; set; }
          public string PhoneNumber{ get; set; }
          public string RatingImageUrl{ get; set; }
          public int NumberOfReviews{ get; set; }
          public string Snippet{ get; set; }
          public string Url{ get; set; }
          public double Latitude{ get; set; }
          public double Longitude{ get; set; }
      }
  }
  </code></pre>
  
  <p>Adding in the method for Review MapYelpBusinessToReview:</p>
  
  <pre><code>    /// &lt;summary&gt;
      /// Maps a &lt;see cref="Y.Data.Business"/&gt; instance to a new &lt;see cref="Review"/&gt;.
      /// &lt;/summary&gt;
      /// &lt;param name="business"&gt;Business object to map.&lt;/param&gt;
      /// &lt;returns&gt;A new &lt;see cref="Review"/&gt; instance.&lt;/returns&gt;
      static Review MapYelpBusinessToReview(Y.Data.Business business) {
          return new Review {
              Id = business.id,
              Name = business.name,
              Address = business.location.address[0],
              City = business.location.city,
              State = business.location.state_code,
              ZipCode = business.location.postal_code,
              PhoneNumber = business.phone,
              RatingImageUrl = business.rating_img_url,
              Snippet = business.snippet_text,
              Url = business.url,
              NumberOfReviews = business.review_count,
  
          };
      }
  </code></pre>