Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IEnumerable<> is defined in an assembly that is not referenced - new NuGet Class Library project

I'm using VS2015 Community, I have .NET 4.6.01040 installed and I followed these instructions to install ASP.NET 5.

I want to start migrating a site from MVC5 to MVC6 all the other updates that came with it, so I started with the Entity Class library project that holds my Data model. This is how my project.json file looks like:

{
  "version": "1.0.0-*",
  "description": "test.Entities Class Library",
  "authors": [ "me" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",
  "frameworks": {
    "net461": {
      "dependencies": { "System.Runtime": "4.0.0.0" }
    },
    "dotnet5.4": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Runtime": "4.0.21-beta-23516",
        "System.Linq": "4.0.1-beta-23516"
        "System.Collections": "4.0.11-beta-23516",
        "System.Threading": "4.0.11-beta-23516"
      }
    }
},
  "dependencies": {
    "EntityFramework.Core": "7.0.0-rc1-final",
  }
}

I changed the framework type from "net451" to "net461" cause I thought that that was the problem, and I also tried to add the reference to the dependencies, but no luck...

The error is happening here:

[NotMapped]
public decimal TotalOrders => Math.Round(Orders.Where(x => x.Code.StartsWith("5")
                             .Sum(x => x.Amount),MidpointRounding.AwayFromZero);

The full error is:

CS0012  The type 'IEnumerable<>' 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'.    test.Entity..NET Framework 4.6

Any idea on how to make this work with the new project types?

like image 465
GregoryHouseMD Avatar asked Nov 19 '15 13:11

GregoryHouseMD


2 Answers

Because it was not clear to me from the answer what was needed, I'll provide it here....

{
  "version": "1.0.0-*",
  "description": "test.Entities Class Library",
  "authors": [ "me" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",
  "frameworks": {
      "net461": {
      "dependencies": { "System.Runtime": "4.0.0.0" },

      "frameworkAssemblies": {
         "System.Runtime": "4.0.10.0"
      }

    },
    "dotnet5.4": {
       "dependencies": {
       "Microsoft.CSharp": "4.0.1-beta-23516",
       "System.Runtime": "4.0.21-beta-23516",
       "System.Linq": "4.0.1-beta-23516"
       "System.Collections": "4.0.11-beta-23516",
       "System.Threading": "4.0.11-beta-23516"
     }
   }
  },
   "dependencies": {
    "EntityFramework.Core": "7.0.0-rc1-final",
  }
}
like image 118
MPavlak Avatar answered Oct 12 '22 23:10

MPavlak


net461 target framework name (TFM) represents the full desktop .NET Framework and if you want to reference System.Runtime from this framework, you need to move the "System.Runtime": "4.0.0.0" entry to frameworkAssembliesnode.

like image 30
Kiran Avatar answered Oct 12 '22 23:10

Kiran