3
votes

I have an asp.net 5 web application that references a class library.

That class library use Entity Framework 7 to perform a query.

public IEnumerable<Member> GetMemberyByFirstName(string firstName)
{
    var members = _context.Members.Where(m => m.FirstName.Contains(firstName));
    return memebers;
}

But I get this compile error

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'. *

2

2 Answers

3
votes

I already figured out how to do this but just wanted the info to available.

It's quite complicated and revolves around the project.json.

The very short answer is I changed the project.json in the class library to

{
    "version": "1.0.0-*",
    "description": "Member.Business Class Library",
    "authors": [ "bryan" ],
    "tags": [ "" ],
    "projectUrl": "",
    "licenseUrl": "",
    "frameworks": {
        "dnx451": { },
        "dnxcore50": {  
            "dependencies": {
               "Microsoft.CSharp": "4.0.1-beta-23516"
            }
        }
    },
    "dependencies": {
        "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
        "Member.DataLayer": "1.0.0-*",
        "Member.Domain": "1.0.0-*",
        "System.Collections": "4.0.11-beta-23516",
        "System.Linq": "4.0.1-beta-23516",
        "System.Runtime": "4.0.21-beta-23516",
        "System.Threading": "4.0.11-beta-23516"
    }
}

Much more detail can be found here - http://nodogmablog.bryanhogan.net/2016/01/the-type-is-defined-in-an-assembly-that-is-not-referenced-system-runtime/

0
votes

try returning like below-

var members = _context.Members.Where(m => m.FirstName.Contains(firstName)).ToList();

Also, I don't understand function definition-

void IEnumerable<Member>

If you want to return IEnumerable<Member> it should only be IEnumerable<Member> and not void IEnumerable<Member>