Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 5 for .NET 6 Support #1109

Closed
ktoim opened this issue Nov 12, 2021 · 19 comments · Fixed by #1122
Closed

Version 5 for .NET 6 Support #1109

ktoim opened this issue Nov 12, 2021 · 19 comments · Fixed by #1122
Labels

Comments

@ktoim
Copy link

ktoim commented Nov 12, 2021

I can see in the README that this package offers .NET 6 support, however upon looking through nuget and the released on GitHub there is no version 5, I also checked branches just to be sure and can't see anything on there.

@ktoim
Copy link
Author

ktoim commented Nov 12, 2021

Also just clarified on looking on AppVeyor to that version 5 does not exist.

@bart-degreed
Copy link
Contributor

That's correct. The documentation website is published from the master branch, which is where we work on v5. We haven't tested against .NET 6 and EF Core 6 yet, but it's a goal we pursue for the stable v5 release. There's no v5 prerelease on NuGet yet, however, we welcome you to try our latest build on .NET 6 and let us know if there are any issues.

What you can also do is try v4 on .NET 6. We'll consider officially supporting .NET 6 with v4 if the fixes are small enough.

@ktoim
Copy link
Author

ktoim commented Nov 12, 2021

Hi bart, thank you for getting back to me and clarifying.

I'm on my phone currently but when trying to run earlier; I couldn't get it to run because of .addJsonApi() so it fell at the first hurdle unfortunately.

I'm willing to be a tester for this; so I will find the error later and see if you can advise anything if that's okay?

@ktoim
Copy link
Author

ktoim commented Nov 12, 2021

So, obviously in .NET 6 the startup has changed.

It appears builder.services.AddJsonApi<AppDbContext>(); is what the issue is relating too.

Unhandled exception. System.MissingMethodException: Method not found: 'System.Type Microsoft.EntityFrameworkCore.Metadata.ITypeBase.get_ClrType()'.

@ktoim
Copy link
Author

ktoim commented Nov 12, 2021

Further:

Just as an added, when I pulled the project down and referenced it locally to use

  • EFCoreVersion: 6.0.0
  • NetCoreAppVersion: net6.0

It worked and from testing so far, everything seems to be good! Would it be possible to get a version of .net6.0 on the AppVeyor feed?

Many thanks!

@bart-degreed
Copy link
Contributor

For the exception you mentioned, can you include the full stack trace? And include which versions of .NET, EF Core, JADNC, and the database provider you used when you got this failure?

About the AppVeyor feed: we use the free tier, which means jobs cannot be run in parallel and each job is restricted to a maximum duration of 1 hour. Running the cibuild already takes a while today (and occasionally times out, the VMs are quite slow), so I'm not looking forward to doubling our build times. However, before crafting a new release I usually run some tests locally against the latest versions of frameworks, just to make sure the basics still work.

@ktoim
Copy link
Author

ktoim commented Nov 12, 2021

@bart-degreed yeah sure, no problem! Thank you for your support on this.

Is there a discord server for this package? Don't worry if not, just might be helpful.

So versions are as follows:

.NET: net6.0
EF Core: 6.0.0

In terms of version for the JADNC, it was the latest master branch so I believe that to be 4.2.0-pre-0855. Hope this helps, I've been actively developing on it since posting that 2 hours ago and not encountered anything thus far.

One thing to note though, there is a few warnings about #nullable annotations context. However, this does not stop the build.

EDIT: I forgot to include the stack trace, my apologies.

Unhandled exception. System.MissingMethodException: Method not found: 'System.Type Microsoft.EntityFrameworkCore.Metadata.ITypeBase.get_ClrType()'.
   at JsonApiDotNetCore.Configuration.ResourceGraphBuilder.Add(DbContext dbContext)
   at JsonApiDotNetCore.Configuration.JsonApiApplicationBuilder.ConfigureResourceGraph(ICollection`1 dbContextTypes, Action`1 configureResourceGraph) in C:\projects\jsonapidotnetcore\src\JsonApiDotNetCore\Configuration\JsonApiApplicationBuilder.cs:line 86
   at JsonApiDotNetCore.Configuration.ServiceCollectionExtensions.SetupApplicationBuilder(IServiceCollection services, Action`1 configureOptions, Action`1 configureAutoDiscovery, Action`1 configureResources, IMvcCoreBuilder mvcBuilder, ICollection`1 dbContextTypes) in C:\projects\jsonapidotnetcore\src\JsonApiDotNetCore\Configuration\ServiceCollectionExtensions.cs:line 51
   at JsonApiDotNetCore.Configuration.ServiceCollectionExtensions.AddJsonApi(IServiceCollection services, Action`1 options, Action`1 discovery, Action`1 resources, IMvcCoreBuilder mvcBuilder, ICollection`1 dbContextTypes) in C:\projects\jsonapidotnetcore\src\JsonApiDotNetCore\Configuration\ServiceCollectionExtensions.cs:line 28
   at JsonApiDotNetCore.Configuration.ServiceCollectionExtensions.AddJsonApi[TDbContext](IServiceCollection services, Action`1 options, Action`1 discovery, Action`1 resources, IMvcCoreBuilder mvcBuilder) in C:\projects\jsonapidotnetcore\src\JsonApiDotNetCore\Configuration\ServiceCollectionExtensions.cs:line 40
   at Program.<Main>$(String[] args) in /Users/ktoim/Apps/JsonApi/JsonApi/JsonApi.Api/Program.cs:line 8

@bart-degreed
Copy link
Contributor

We use gitter chat instead of discord.

Thanks for providing the details. I did some experiments myself. First, I created a simple .NET 6 WebApi project by following the steps from Getting Started and ended up with the following in Program.cs:

using DemoWebApiOnDotNet6.Data;
using DemoWebApiOnDotNet6.Resources;
using JsonApiDotNetCore.Configuration;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDbContext<AppDbContext>(options => options.UseNpgsql(
    "Host=localhost;Port=5432;Database=DotNet6Example;User ID=postgres;Password=postgres"));

builder.Services.AddJsonApi<AppDbContext>();

var app = builder.Build();

app.UseRouting();
app.UseJsonApi();
app.MapControllers();

using (var scope = app.Services.CreateScope())
{
    var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
    dbContext.Database.EnsureDeleted();
    dbContext.Database.EnsureCreated();

    dbContext.People.Add(new Person { Name = "John Doe" });
    dbContext.SaveChanges();
}

app.Run();

For this demo API, I found the following:

  • NuGet reference to JADNC v4.2 on .NET 6 and EF Core 3.1 using PostgreSQL: works
  • NuGet reference to JADNC v4.2 on .NET 6 and EF Core 5 using PostgreSQL: works
  • NuGet reference to JADNC v4.2 on .NET 6 and EF Core 6 using PostgreSQL: runtime exception at application startup, because EF Core 6 has binary breaking changes

Next, I opened the solution from the master branch and found the following:

  • Switched to .NET 6 with EF Core 5 using PostgreSQL: all tests pass, despite nullability warnings during build, due to richer annotations and fixes in ASP.NET libraries
  • Switched to .NET 6 with EF Core 6 using PostgreSQL: 413/1729 tests fail, more nullability warnings because EF Core 6 got annotated too. After adding global AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); as suggested here, still 66 failing tests.

Then I opened the solution from the 4.2 release branch and found the following:

  • Switched to .NET 6 with EF Core 3.1 using PostgreSQL: all tests pass
  • Switched to .NET 6 with EF Core 5 using PostgreSQL: all tests pass
  • Switched to .NET 6 with EF Core 6: 367/1859 tests fail, after setting EnableLegacyTimestampBehavior all tests succeed

Conclusion: Using .NET 6 seems to work fine, EF Core 6 has issues that we'll need to investigate. Note that all the above applies to a fresh start with an empty database, which is usually not very realistic. The release notes of PostgreSQL sum it up pretty well:

Npgsql 6.0 brings some major breaking changes and is not a simple in-place upgrade. Carefully read the breaking change notes below and upgrade with care.

@ktoim
Copy link
Author

ktoim commented Nov 13, 2021

@bart-degreed i forgot to mention I was actually using SQLServer for my current application and didn't encounter errors.

What do you recommend moving forward? Keep the latest version up to date locally so it's eligible for use?

I haven't encountered any issues thus far but am keen to explore and upgrade my application to .NET 6 😀.

@bart-degreed
Copy link
Contributor

Thanks for trying out the latest bits. We have a rule that each PR merge should improve the codebase, so we won't be merging half work to master. This means you can safely use the master branch until we have a prerelease out. However, you may face breaking changes until the stable v5, which we generally document in the PR descriptions. Aside from the general list of breaking changes in EF Core 6, I haven't found documents online for the SQL Server provider, so you should be fine.

I've been thinking about what we can do for JADNC v4. It seems fine to support .NET 6, but not EF Core 6 due to its binary breaking changes. Even if we multi-targeted JADNC against .NET 5 with EF Core 5 and .NET 6 with EF Core 6, it would mean that using .NET 6 with EF Core 5 is no longer possible because NuGet does not support forcing a different TFM (see here and here). So this would be a breaking change in JADNC v4 for existing users that have already upgraded to .NET 6, which we cannot do.

In the master branch, we currently target .NET 5 with EF Core 5, but we aim to support running against .NET 6 and EF Core 6 in the first prerelease. We could achieve supporting both the 5.x versions and the 6.x versions using multi-targeting, but given the various breaking changes in JADNC v5 already, I think it's reasonable to support just .NET 6 with EF Core 6. Yet we may still choose to multi-target, based on substantial community feedback. However, we'd like to wait a few weeks before updating master, until the first maintenance fixes for .NET 6 and EF Core 6 are out, as well as tooling updates (Resharper is currently in EAP) and dependent packages. While it's tempting to develop against the latest and greatest, dive into all sorts of bugs, create issues, workarounds, etc, we're expected to remain productive. Though I'll keep an eye out for what's coming, as well as listen to the JADNC community feedback.

I hope this gives some perspective on what to expect in the near future, as well as invite users to provide feedback on our plans.

@ktoim
Copy link
Author

ktoim commented Nov 15, 2021

@bart-degreed that's amazing thank you for getting back in touch with me and taking the time to investigate.

Is there a place where I can if I experience issues with JADNC to post. Wherever is best for yourself for visibility.

Much appreciated.

@bart-degreed
Copy link
Contributor

Opening separate issues for different problems would work best. It enables us to solve them separately and link PRs to them.

@ktoim
Copy link
Author

ktoim commented Nov 15, 2021

@bart-degreed Not a problem! I'll go ahead and close this issue and raise anymore that I may come across.

Thank you for your brilliant work on the package!

@ktoim ktoim closed this as completed Nov 15, 2021
@bart-degreed
Copy link
Contributor

Reopening to track the work needed for .NET 6 support. Linked from roadmap to here.

@bart-degreed bart-degreed reopened this Nov 15, 2021
@ThomasBarnekow
Copy link

Hi @bart-degreed,

Running the cibuild already takes a while today (and occasionally times out, the VMs are quite slow)

That is definitely true. One set of activities that takes relatively long is this:

RunInspectCode
RunCleanupCode

On Linux (Ubuntu image), RunInspectCode takes a whopping 16 to 18 minutes (yes, minutes) whereas it "only" takes 4 to 5 minutes on Windows (Visual Studio 2019 image). RunCleanupCode takes 2 to 4 minutes on Linux and 1 to 2 minutes on Windows. In total, we are talking about roughly 18 to 22 minutes on Linux and 5 to 7 minutes on Windows. Overall RunInspectCode accounts for roughly half of the total time on Linux.

The question is why you need to run:

  • both steps as part of the cibuild and
  • those two steps in both images (Ubuntu and Visual Studio 2019).

If possible, you should only run this on Windows.

@bart-degreed
Copy link
Contributor

bart-degreed commented Nov 17, 2021

We need to run Linux before Windows, because the Windows build publishes the NuGet package and the documentation website. We'd like to fail fast on formatting issues, not wait for the whole Linux build to complete first. During regular work, formatting issues are usually the cause for failure. Instead of running cleanup locally, we queue up a build and work on something else meanwhile.

I know how frustrating it can be to have to wait on cibuild when working on that, so by all means disable steps temporarily to be productive.

@ThomasBarnekow
Copy link

I'll open a separate issue for discussing the build topic because you are right: it has been the most frustrating experience.

@ziali088
Copy link

Unhandled exception. System.MissingMethodException: Method not found: 'System.Type Microsoft.EntityFrameworkCore.Metadata.ITypeBase.get_ClrType()'.

I've also come across this error when starting a new .NET 6 project, downgrading to EF 5 worked.

@bart-degreed
Copy link
Contributor

@ziali088 See /~https://github.com/json-api-dotnet/JsonApiDotNetCore#compatibility. You'll need to clone/download the repo and build from source to use EF Core 6 currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

4 participants