网站在Visual Studio中工作但在服务器上中断。获取错误:" System.NullReferenceException:对象引用未设置为对象的实例。" 我重新发布了这个项目,但仍然存在错误。我从服务器上取下了文件,它仍可在我的机器上运行,但不能在服务器上运行。可能会发生什么?
<div class="main">
<h2 class="queue_title">Queue</h2>
@if (Model.Count > 0)
{
<table class="inputTableLeft">
<tr><th>Company</th><th>Category</th><th>Assigned Resource</th></tr>
<tr>
<td>
<select id="CompanySelect">
<option value="0">All</option>
@foreach (var company in Model.GroupBy(r => r.Company))
{
<option value="@company.First().Company">@company.First().Company</option>
}
</select>
</td>
<td>
<select id="CategorySelect">
<option value="0">All</option>
@foreach (var category in Model.GroupBy(r => r.Category))
{
<option value="@category.Key.Id">@category.Key.Name</option>
}
</select>
</td>
<td>
<select id="AssignedResource">
<option value="0">All</option>
@foreach (var resource in Model.GroupBy(r => r.AssignedUserName))
<!--Breaking here:-->{
<option value="@resource.First().AssignedADUser.FullName">@resource.First().AssignedADUser.FullName</option>
}
</select>
</td>
</tr>
</table>
<table class="inputTableRight">
<tr>
<th>Incident/Ticket Number</th><th>RCA Number</th>
</tr>
<tr>
<td>
<input type="text" id="IncidentNumFilter" />
</td>
<td>
<input type="text" id="RCANumFilter" />
</td>
</tr>
</table>
<table id="QueueTable">
<tr>
@foreach (var grp in Model.GroupBy(r => r.StatusId))
{
<th>
@grp.First().Status.Name
</th>
}
</tr>
<tr>
@foreach (var grp in Model.GroupBy(r => r.StatusId))
{
<td data-status="@grp.First().StatusId">
@foreach (RCAModel rca in grp.OrderBy(r => r.CreateTime).OrderByDescending(r => r.Critical))
{
<div data-rca="@rca.Id" data-company="@rca.Company" data-assigned="@rca.AssignedADUser.FullName" data-category="@rca.Category.Id" data-incident="@rca.TicketNumber" class="line @(rca.Critical ? "highlight_red" : "")">
<a href="@Url.Action("EditRCA", new { id = rca.Id })" >
@rca.Id : Created - @rca.CreateTime @(rca.Critical ? Html.Label("expression", " - CRITICAL") : Html.Label("", ""))
</a>
</div>
}
</td>
}
</tr>
</table>
}
else
{
@: No RCAs in queue
}
</div>
答案 0 :(得分:2)
你可能从这个链中的某个地方得到一个空值:
@resource.First().AssignedADUser.FullName
在此代码周围添加一些日志记录和一些空检查,以找出什么是null。
例如:
var firstRes = resource.First();
if (firstRes != null)
{
var user = firstRes.AssignedADUser
if (user != null)
{
// Do your normal work.
}
else
{
// Log a message here
}
}
else
{
// Log a message here
}