Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Analyzer Erroneously Reports Incompatibilities for EF Core projects #993

Closed
JeremyLikness opened this issue Sep 14, 2021 · 9 comments
Closed
Labels

Comments

@JeremyLikness
Copy link

JeremyLikness commented Sep 14, 2021

I made a simple project with EF Core 3.1 on .NET 4.7.2. It ran fine. I then ran the portability analyzer and it flagged several EF Core constructors, methods, and properties as incompatible with multiple various of .NET Core and .NET 5. Report is attached. To verify these are invalid incompatibilities, I used the upgrade assistant to upgrade from .NET 4.7.2 to .NET 5. It upgraded with no issue and ran fine after the upgrade.

Reproduce:

  1. Create a new .NET 4.7.2 console application
  2. Add a package reference to Microsoft.EntityFrameworkCore.Sqlite version 3.1.19
  3. Paste this code to Program.cs
  4. Run the portability analyzer

Program.cs:

using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;

namespace NetFXConsole
{

namespace NetFXConsole
{
    public class Planet
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

    public class SolarContext : DbContext
    {
        public DbSet<Planet> Planets { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlite("Data Source=solarsytem.sqlite");
            base.OnConfiguring(optionsBuilder);
        }
    }

    class Program
    {
        static void Main(string[] _)
        {
            using (var solarsystem = new SolarContext())
            {
                solarsystem.Database.EnsureDeleted();
                solarsystem.Database.EnsureCreated();
                var planets = new[]
                {
                    "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"
                }.Select(p => new Planet { Name = p });
                solarsystem.Planets.AddRange(planets);
                solarsystem.SaveChanges();
                var thirdPlanet = solarsystem.Planets.OrderBy(p => p.Id).Skip(2).Take(1).First();
                Console.WriteLine($"The third planet I found is {thirdPlanet.Name}.");
            }
        }
    }
}

portability

@Lxiamail
Copy link
Member

Lxiamail commented Oct 6, 2021

I created the repro based in above steps, and apiport analyze report shows that Microsoft.EntityFrameworkCore.dll not 100% compatable with .NET5 even though it is .netstandard v2 dll, which doesn’t make sense. APIPort tool uses .NET API Catalog (apisof.net) as backend data.

@ericstj and @terrajobst

Looking into APICatalog, .NET API Catalog (apisof.net) shows that Microsoft.EntityFrameworkCore.dll APIs like NotParameterizedAttribute class is only supported on .NET6, do you know why this that? Looking into .Net doc, it shows that it is supported from v1.0 to v5.0.

@JeremyLikness
Copy link
Author

Hi @ericstj @terrajobst @Lxiamail is there any update or plans to update this?

@JeremyLikness
Copy link
Author

Following up, I asked for an update on #993. Will update again when I hear back.

@ericstj
Copy link
Member

ericstj commented Mar 3, 2022

I'm not familiar with the API catalog data, @terrajobst @carlossanlop do either of you know how API catalog represents nuget packages like EF?

@Pilchie
Copy link
Member

Pilchie commented Mar 11, 2022

Note that I'm not seeing this today. I see a few members that aren't supported on .NET 5. APIPort doesn't say anything about .NET 6, but apisof says that those APIs are supported in 6. Specifically Microsoft.EntityFrameworkCore.Infrastructure.SqliteDbContextOptionsBuilder and Microsoft.EntityFrameworkCore.SqliteDbContextOptionsBuilderExtensions.UseSqlite are the only things marked as problematic.

@Pilchie
Copy link
Member

Pilchie commented Mar 11, 2022

I wonder if that's because of "Skip Microsoft .NET assemblies" in v2.8.10-alpha from https://github.com/microsoft/dotnet-apiport/releases/tag/v2.8.10-alpha

@terrajobst
Copy link
Member

terrajobst commented Mar 12, 2022

@Lxiamail

Looking into APICatalog, .NET API Catalog (apisof.net) shows that Microsoft.EntityFrameworkCore.dll APIs like NotParameterizedAttribute class is only supported on .NET6, do you know why this that? Looking into .Net doc, it shows that it is supported from v1.0 to v5.0.

apisof.net has the version 6.0 of the package indexed. That package includes a .NET 6 only binary, so the displayed data seems correct.

@ericstj

I'm not familiar with the API catalog data, @terrajobst @carlossanlop do either of you know how API catalog represents nuget packages like EF?

API Port (the tool in this repo) doesn't use apisof.net as the backend, it has its own API Port backend which is populated from our old internal SQL Server based API Catalog which doesn't understand packages. It was populated with flat folders, because when we initially built it we only had to support old-school targeting pack based frameworks. .NET Core v1 came later. We worked this around by introducing the fake frameworks "<platform> <version> + Platform Extensions" which included the platform assemblies plus some set of assemblies we restored from certain NuGet packages. That's why EF shows up as supported in those but not in .NET 5 because that just contains the platform API and EF is an OOB.

The proper fix for this would be to update API Port to use the data that apisof.net is using, which would include OOB package information as well.

@JeremyLikness
Copy link
Author

What are next steps? @Lxiamail @ericstj @Pilchie do you need anything from me to move forward based on the "proper fix" explanation by @terrajobst?

@terrajobst
Copy link
Member

Closing as API Port was deprecated in favor of binary analysis in .NET Upgrade Assistant.

@terrajobst terrajobst closed this as not planned Won't fix, can't repro, duplicate, stale Nov 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants