17

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!

4 Answers 4

17

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.

0
0

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.

0

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

0

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>

Not the answer you're looking for? Browse other questions tagged or ask your own question.