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

Can't use new Npgsql.EntityFrameworkCore.PostgreSQL 9.x types with Aspire.Npgsql.EntityFrameworkCore.PostgreSQL 9.x in .NET 8 #7749

Open
1 task done
julioct opened this issue Feb 23, 2025 · 0 comments
Labels
area-integrations Issues pertaining to Aspire Integrations packages postgres Issues related to Postgres integrations

Comments

@julioct
Copy link
Contributor

julioct commented Feb 23, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Aspire.Npgsql.EntityFrameworkCore.PostgreSQL Version="9.0.0" depends on Npgsql.EntityFrameworkCore.PostgreSQL >= 8.0.11 when you target the net8.0 platform.

However, Npgsql.EntityFrameworkCore.PostgreSQL 9.0.3 also targets the net8.0 platform, so Aspire.Npgsql.EntityFrameworkCore.PostgreSQL should depend on However, Npgsql.EntityFrameworkCore.PostgreSQL >= 9.0.3.

Because of this, if you try to use Aspire.Npgsql.EntityFrameworkCore.PostgreSQL when targeting .NET 8, you lose all the new stuff available in Npgsql.EntityFrameworkCore.PostgreSQL 9.0.x, like the ability to use ConfigureDataSource, as in here:

  builder.Services.AddNpgsql<MyDbContext>("the connection name", dbContextOptionsBuilder =>
      dbContextOptionsBuilder.ConfigureDataSource(dataSourceBuilder =>
          {
              dataSourceBuilder.UsePeriodicPasswordProvider(
                  async (_, cancellationToken) =>
                  {
                      var credentials = new DefaultAzureCredential(credentialOptions);
                      var token = await credentials.GetTokenAsync(
                          new TokenRequestContext(["https://ossrdbms-aad.database.windows.net/.default"]),
                          cancellationToken
                      );
                      return token.Token;
                  },
                  TimeSpan.FromHours(24),
                  TimeSpan.FromSeconds(10)
              );
          })
  );

In fact, if in your .NET 8 project you switch from Npgsql.EntityFrameworkCore.PostgreSQL to Aspire.Npgsql.EntityFrameworkCore.PostgreSQL (both version 9.x), your project immediately breaks, should should not be the case.

Expected Behavior

In .NET 8 projects, when using Aspire.Npgsql.EntityFrameworkCore.PostgreSQL 9.x you should be able to use everything available in Npgsql.EntityFrameworkCore.PostgreSQL 9.x.

Steps To Reproduce

  1. Get a reference to Aspire.Npgsql.EntityFrameworkCore.PostgreSQL 9.x:

dotnet add package Aspire.Npgsql.EntityFrameworkCore.PostgreSQL --version 9.0.0

  1. Write this code:
  builder.Services.AddNpgsql<MyDbContext>("the connection name", dbContextOptionsBuilder =>
      dbContextOptionsBuilder.ConfigureDataSource(dataSourceBuilder =>
          {
              dataSourceBuilder.UsePeriodicPasswordProvider(
                  async (_, cancellationToken) =>
                  {
                      var credentials = new DefaultAzureCredential(credentialOptions);
                      var token = await credentials.GetTokenAsync(
                          new TokenRequestContext(["https://ossrdbms-aad.database.windows.net/.default"]),
                          cancellationToken
                      );
                      return token.Token;
                  },
                  TimeSpan.FromHours(24),
                  TimeSpan.FromSeconds(10)
              );
          })
  );
  1. The code won't compile due to lack of ConfigureDataSource method.

Exceptions (if any)

No response

.NET Version info

.NET SDK:
Version: 8.0.406
Commit: 73c77e847d
Workload version: 8.0.400-manifests.f7661779
MSBuild version: 17.11.22+17752cebd

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.406\

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
There are no installed workloads to display.

Host:
Version: 8.0.13
Architecture: x64
Commit: eba546b0f0

.NET SDKs installed:
8.0.406 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
None

Environment variables:
Not set

global.json file:
Not found

Anything else?

ASP.NET Core version: 8
.NET Aspire version: 9
IDE: VS Code

@DamianEdwards DamianEdwards added area-integrations Issues pertaining to Aspire Integrations packages postgres Issues related to Postgres integrations labels Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-integrations Issues pertaining to Aspire Integrations packages postgres Issues related to Postgres integrations
Projects
None yet
Development

No branches or pull requests

2 participants