20

I am getting the following error when I try to use version 4.0.30506 (unfortunately we are tied to this version of ASP.NEt Web API for now) of the Microsoft.AspNet.WebApi.HelpPage nuget package. I am using Windows 7 and .NET 4.5.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: 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'.

Source Error:


Line 11: 
Line 12:     // Group APIs by controller
Line 13:     ILookup<string, ApiDescription> apiGroups = Model.ToLookup(api => api.ActionDescriptor.ControllerDescriptor.ControllerName);
Line 14: }
Line 15: 

enter image description here

As far as I can see I have all the correct references for this to work. I have tried looking for a System.Runtime assembly as it suggests, but I can't find it on my system. I have added using statements to the top of Index.cshtml, but with no affect.

@using System
@using System.Runtime

Any suggestions of what is causing this error?

Jim Jeffries
  • 9,841
  • 15
  • 62
  • 103
  • Possible duplicate of [What does the web.config compilation/assemblies element do?](https://stackoverflow.com/questions/16675171/what-does-the-web-config-compilation-assemblies-element-do) – Michael Freidgeim May 30 '17 at 08:07

3 Answers3

28

check your web.config:

<compilation debug="true" targetFramework="4.5">
    <assemblies>
        <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </assemblies>
</compilation>
giammin
  • 18,620
  • 8
  • 71
  • 89
4

In my case, this error disappeared when I removed System.Collections.Immutable.dll from Bin directory. This DLL is from NuGet package and is available only for Win8 platforms and I was working with Win7. So it might help you too..

RMalke
  • 4,048
  • 29
  • 42
Lukas Dvorak
  • 481
  • 4
  • 15
  • I have added then removed the `System.Collections.Immutable.dll` and start getting the error. After deleting it from bin, the error was gone. – RMalke Oct 14 '15 at 20:44
2

I ran into this error after updating all Nuget packages in an MVC 5, .NET 4.5.1 project, and thanks to Dmitry Lyalin's post discovered the issue related to an updated Nuget package that has become a Portable Class Library.

For those who like to dig, I figured out the culprit by doing the following:

  1. Unload the project unloading a VS project
  2. Edit the project
    editing a project
  3. Search for "portable" found an unexpected portable library
  4. Having found Humanizer, I changed it back to pre-PCL version 1.37.7, retested the page, and found that everything worked again.

Knowing the culprit(s), Humanizer in my case, there's two options:

  1. Cap the Humanizer Nuget at version 1.x.y so as not to use the new PCL libraries in v2 via allowedVersions attribute in packages.config:
    <package id="Humanizer " version="1.37.7" allowedVersions="[1,2)" />
  2. Do what giammin suggests in his answer and add the System.Runtime assembly under system.web in web.config:
    <system.web><compilation ...><assemblies><add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /></assemblies></compilation></system.web>
Jeremy Cook
  • 20,840
  • 9
  • 71
  • 77