Note that there are some explanatory texts on larger screens.

plurals
  1. POFor loop errors on call
    primarykey
    data
    text
    <p>I have the following code</p> <pre><code>List&lt;WorkingRecord&gt; recordListz = new List&lt;WorkingRecord&gt;(); -----other unrelated code---------- recordListz = IF_Export(out ifRecCount,out WrittenRecords); for (int i = 0; i &lt; recordListz.Count; i++) { //do something } </code></pre> <p>recordListz is created ok (well sort of but more on that later), the IF_Export method retuns the list ok and then if I put the breakpoint on the for loop and hover over the recordListz object it looks fine (with 10 records in it) and the count reports 10 records too. However as soon as I try to execute the loop the code errors claiming "Object not set to instance of an object" (non of the objects in the list are null). Plus if I put a quick watch on the object at this point it claims the value is ['' is null].</p> <p>Now on to the issue with creating the recordListz object in the first place.... There is actually some other code (completely unrelated to the code above) between the instantiation of recordListz and the method call. Originally I had the following code</p> <pre><code>List&lt;WorkingRecord&gt; recordListz = IF_Export(out ifRecCount,out WrittenRecords); </code></pre> <p>However this resulted in an error of "Object not set to an instance of an object", even though the method being called returned a perfectly fine list (confirmed by placing a breakpoint on the return line of the method).</p> <p>I then broke it out to the following</p> <pre><code>List&lt;WorkingRecord&gt; recordListz = new List&lt;WorkingRecord&gt;(); recordListz = IF_Export(out ifRecCount,out WrittenRecords); </code></pre> <p>However this errored on the first line with "Object not set to an instance of an object". I have exactly the same line which is called in the IF_Export method which works fine and is in the same class as the code calling it...</p> <p>Moving the line to the top of the code stopped this from erroring, but this then results in the loop error.</p> <p>What on earth is going on, I have never seen this before.</p> <p>-----------------------UPDATE-------------------</p> <p>Ok if I have the following code</p> <pre><code>-----other unrelated code---------- List&lt;int&gt; WrittenRecords=new List&lt;int&gt;(); List&lt;WorkingRecord&gt; recordListz = new List&lt;WorkingRecord&gt;(); recordListz = IF_Export(out ifRecCount,out WrittenRecords); for (int i = 0; i &lt; recordListz.Count; i++) { //do something } </code></pre> <p>The recordListz instantiation line errors with "object not set to instance of an object</p> <p>However if I have the following code</p> <pre><code>-----other unrelated code---------- List&lt;WorkingRecord&gt; recordLista = new List&lt;WorkingRecord&gt;(); List&lt;int&gt; WrittenRecords=new List&lt;int&gt;(); List&lt;WorkingRecord&gt; recordListz = new List&lt;WorkingRecord&gt;(); recordListz = IF_Export(out ifRecCount,out WrittenRecords); for (int i = 0; i &lt; recordListz.Count; i++) { //do something } </code></pre> <p>Then recordListz instantiation still errors, but recordLista instantiation works fine!</p> <p>Plus if I have the following code</p> <pre><code>-----other unrelated code---------- List&lt;int&gt; WrittenRecords=new List&lt;int&gt;(); List&lt;WorkingRecord&gt; recordLista = new List&lt;WorkingRecord&gt;(); List&lt;WorkingRecord&gt; recordListz = new List&lt;WorkingRecord&gt;(); recordListz = IF_Export(out ifRecCount,out WrittenRecords); for (int i = 0; i &lt; recordListz.Count; i++) { //do something } </code></pre> <p>recordLista also works fine!</p> <p>--------Another Update------</p> <p>If I put in the following code</p> <pre><code>-----other unrelated code---------- List&lt;int&gt; WrittenRecords=new List&lt;int&gt;(); List&lt;WorkingRecord&gt; recordLista = new List&lt;WorkingRecord&gt;(); List&lt;WorkingRecord&gt; recordListz = new List&lt;WorkingRecord&gt;(); recordLista = IF_Export(out ifRecCount,out WrittenRecords); for (int i = 0; i &lt; recordLista.Count; i++) { //do something } </code></pre> <p>It is now recordLista instantiation that errors..........</p> <p>--------Update 3---------------</p> <p>Ok, I have found at which point the strange things are happening.</p> <p>The code sits inside an if statement</p> <pre><code>if (dsExportRecords != null &amp;&amp; dsExportRecords.Tables[0].Rows.Count != 0) </code></pre> <p>dsExportRecords is a dataset. If I put my code immediately within the if statement then the strange things happen, however if it is immediately before the if statement then everything is fine.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload