Note that there are some explanatory texts on larger screens.

plurals
  1. POObject reference not set while SQL manager says it is
    primarykey
    data
    text
    <p>Lately I have run in a strange NullReferenceException. It pops up only occasionally why it is so hard to debug it for me. Today it happened again and I want to fix it now I have the error.</p> <p>I have the following setup:</p> <p>An asp.net view with relevant code:</p> <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;WerkStageNu.Profiles&gt;" %&gt; &lt;%@ Import Namespace="WerkStageNu.Helpers" %&gt; &lt;div class="listing"&gt; &lt;div class="content"&gt; &lt;h3&gt;&lt;%=Html.ActionLink(Model.Persons.UserName, "Details", new { id = Model.ID } )%&gt;&lt;/h3&gt; </code></pre> <p>And when running this it tells me that Model.Persons is null giving the following error, while the Model itself is loaded with the data from the (SQL) Database. I am using ADO.net entities. Retrieving the profile instead of using the model resulted in the same error.</p> <pre><code>&lt;%=Html.ActionLink(WerkStageNu.Models.Repository.Instance.GetProfileByID(Model.ID) .Persons.UserName, "Details", new { id = Model.ID } )%&gt; </code></pre> <p>Did not do any good.</p> <p>Some error images:</p> <p><a href="http://www.bastijn.nl/zooi/model_persons.png" rel="nofollow noreferrer">debug mode http://www.bastijn.nl/zooi/model_persons.png</a></p> <p><a href="http://www.bastijn.nl/zooi/stacktrace.png" rel="nofollow noreferrer">stack trace http://www.bastijn.nl/zooi/stacktrace.png</a></p> <p>So far it seems a normal error, but when I checked my DB behind the request I found that this field is filled in and that the link is correct. SQL manager screens to show this information:</p> <p>Profiles table:</p> <p><a href="http://www.bastijn.nl/zooi/profiles_sql.png" rel="nofollow noreferrer">profiles DB http://www.bastijn.nl/zooi/profiles_sql.png</a></p> <p>Persons table:</p> <p><a href="http://www.bastijn.nl/zooi/persons_sql.png" rel="nofollow noreferrer">persons DB http://www.bastijn.nl/zooi/persons_sql.png</a></p> <p>As one can see all the PersonIDs are set so normally all the links should be loaded? Sometimes this is the case, but sometimes however this nullreference pops up from out of nowhere. Am I forgetting something? Should I manually load something?</p> <p><strong>//edit</strong></p> <p>I notice</p> <p>&lt;% Model.PersonsReference.Load(); Model.EmploymentsReference.Load(); %> <em>Fixes this problem, the question is why I need it here and not throughout the rest of my views using the same approach?</em></p>
    singulars
    1. This table or related slice is empty.
    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.
 

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