Why is Visual Studio telling me I need to reference System.Private.CoreLib?

烈酒焚心 提交于 2019-12-06 19:19:51

问题


I'm trying out EF Core for the first time and have coded a very simple MVC app to get my feet wet. I am using a method for seeding the database found in the UnicornStore project where they write some code in Startup.cs to migrate the database and then run a seed method.

Before they call the seed method, they run this DbContext extension method to check if all migrations have been applied:

using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;

namespace UnicornStore.Models
{
    public static class DbContextExtensions
    {
        public static bool AllMigrationsApplied(this DbContext context)
        {
            var applied = context.GetService<IHistoryRepository>()
                .GetAppliedMigrations()
                .Select(m => m.MigrationId);

            var total = context.GetService<IMigrationsAssembly>()
                .Migrations
                .Select(m => m.Key);

            return !total.Except(applied).Any();
        }
    }
}

I've put this same method in my application and everything works -- the code compiles and the database is migrated and seeded. However, Visual Studio (2017 Enterprise) is red underlining this line:

context.GetService<IMigrationsAssembly>()
                    .Migrations
                    .Select(m => m.Key);

If I hover over the red line, it tells me:

Module 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=foo' should be referenced

Can anyone tell me why I am getting this message? I actually tried to add a reference to System.Private.CoreLib to see what would happen, and that caused a ton of errors (undefined System.Object, etc). I'm never comfortable leaving things like this unresolved in case they come back to bite me later, so any resolution (or a confirmation that I can leave this be and ignore the message) would be appreciated!


回答1:


Do you have R# installed? You might have been hitting this issue: RSRP-464676

If so, try suspending R# and see if the issues are not shown anymore.




回答2:


Just as an alternate response, it seems as if my happy-go-lucky alt-enter spam led me to import an assembly reference to System.Private.CoreLib, which I think was from a threading namespace import fix. Check to see whether this has been referenced.




回答3:


I had the same problem. Upgrading to the latest version of Resharper fixed the issue.



来源:https://stackoverflow.com/questions/44183208/why-is-visual-studio-telling-me-i-need-to-reference-system-private-corelib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!