EDIT: I have checked and attempted a lot of the other Assembly Not Referenced issues found on SE, but I haven't found many dealing with what should be a built-in assembly (System.Collections.Generic.List<t>
). This makes it difficult to manually add or remove the reference etc.
I am trying to build a PartialView from an API response. I have confirmed the response is correct and well-formed, my objects are being built correctly, but when I generate the Partial View, a Compilation Error is instead shown.
Compiler Error Message: CS0012: The type 'System.Collections.Generic.List`1<T0>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Here is the Razor view:
@using OpsComponent
@model OpsComponent.ComponentData
<div class="row">
<div class="col-md-6">
<ul class="list-group">
@foreach (Data metric in Model.Metrics)
{
<li class="list-group-item">
<span class="badge">@metric.Value</span>
@metric.Key<br/>
</li>
}
</ul>
</div>
</div>
And here is the Data class definition:
public class Data
{
public string Key { get; set; }
public string Value { get; set; }
public string Source { get; set; }
public Status Status { get; set; }
}
Where Status is an enum. I have checked in Debugging that the Model object is correct and well-formed before it is passed to the PartialView, but instead of a correct layout, I get the Server Error screen and a 500 response.
at the line @foreach (Data metric in Model.Metrics)
Action code for completeness:
public ActionResult ComponentDetail(string id)
{
var data = Client.GetComponentData(id.DecodeBase64ToString());
var partialViewResult = PartialView("_ComponentDetail", data);
return partialViewResult;
}