title: Object reference not set to an instance of an object when creating observable collection from list
body: <p>In my application, I am creating observable collection from list.
  List is collection of my database Table.
  List display correct result but when i create observable collection it gives me Exception as
  <code>Object reference not set to an instance of an object</code>.
  And this happend some times when i run my application with large Database.For small database it works fine.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>var list = db.Contacts.ToList();
  ObservableCollection collection = new ObservableCollection(list);
  </code></pre>
  
  <p>Exception:</p>
  
  <p><strong>Object reference not set to an instance of an object</strong></p>
  
  <p><strong>Stack Trace</strong></p>
  
  <pre><code> at System.Data.Linq.IdentityManager.StandardIdentityManager.InsertLookup(MetaType type, Object instance)
     at System.Data.Linq.CommonDataServices.InsertLookupCachedObject(MetaType type, Object instance)
     at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReaderBase`1.InsertLookup(Int32 iMetaType, Object instance)
     at Read_Contact(ObjectMaterializer`1 )
     at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext()
     at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
     at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
     at System.Linq.OrderedEnumerable`1.&lt;GetEnumerator&gt;d__0.MoveNext()
     at System.Collections.ObjectModel.ObservableCollection`1.CopyFrom(IEnumerable`1 collection)
     at System.Collections.ObjectModel.ObservableCollection`1..ctor(IEnumerable`1 collection)
  </code></pre>
  
  <p><strong>Target Site</strong></p>
  
  <pre><code>{System.Object InsertLookup(System.Data.Linq.Mapping.MetaType, System.Object)}
  </code></pre>
  
  <p>What i am doing wrong?
  Thanx in advance</p>
  
  <hr>
  
  <p><strong>Edit:</strong></p>
  
  <p>Above is only a small part of my code. In my actual code, I use UnitOfWork and Repository Pattern. To debug the problem I tried to print all the ID's of entities via <code>foreach</code> loop.</p>
  
  <pre><code>  foreach (var item in _uow.Contacts.Query(q =&gt; !q.ContactID.Equals(1)))
    {
       i = item.ContactID;
    }
  </code></pre>
  
  <p>But suddenly after some 25534 (random figures everytime I get), <code>_uow.Contacts.Query(q =&gt; !q.ContactID.Equals(1)</code> is not able to get the next element. In other words Enumerator.MoveNext() isn't performed. Of course this may be if next element is <code>null</code>, but it isn't. I have added a Watch to list to confirm it.</p>