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

asp.net-core asp.net-core-mvc entity-framework-core visual-studio

Question

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
15
5/25/2017 2:35:07 PM

Accepted Answer

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.

15
6/7/2017 6:56:16 AM

Popular Answer

Had a similar problem in VS Code (vscode) with SAFE-Stack's server template code. The issue appears resolved by adding <Reference include="netstandard" /> to the associated fsproj project file sugggested on github here as follows:

<Project Sdk="Microsoft.NET.Sdk.Web">
  ..
  <ItemGroup>
    ..
    <Reference include="netstandard" />
    ..
  </ItemGroup>
</Project>


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow