Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net MVC EditorFor "The type 'System.Object' is defined in an assembly that is not referenced" error

@using (Html.BeginForm("Index", "Employees", FormMethod.Post, new { encType = "multipart/form-data", name = "EmployeeForm" }))
{
<table class="table table-bordered table-condensed table-striped">
    <tr>
        <th>
            Name
        </th>
        <th>
            Surname
        </th>
        <th>
            ID Number
        </th>
        <th>
            Email
        </th>
        <th>
            Birthdate
        </th>
        <th>
            Action
        </th>
    </tr>
    @Html.EditorFor(model => model.Employees)
</table>
}

This line Line 32: @Html.EditorFor(model => model.Employees) gives the following Error

CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

I have used this similiar approach in another project which did not give this error.

like image 336
Donald Jansen Avatar asked Jul 06 '15 08:07

Donald Jansen


1 Answers

Look for this in your web.config:

<compilation debug="true" targetFramework="4.5"/>

Add the System.Runtime assembly as follows:

 <compilation debug="true" targetFramework="4.5">
      <assemblies>     
        <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />   
      </assemblies>
    </compilation>

This is usually caused due to MVC and PCL as detailed in the following article:

The type ‘System.Object’ is defined in an assembly that is not reference (MVC + PCL issue)

like image 120
hutchonoid Avatar answered Sep 30 '22 13:09

hutchonoid