Skip to content

.NET 7 Blocker - Method get_ServerSideSessions in type ApiAuthorizationDbContext from assembly IdentityServer does not have an implementation #46025

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

Closed
1 task done
Alan468 opened this issue Jan 11, 2023 · 6 comments
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-spa ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved

Comments

@Alan468
Copy link

Alan468 commented Jan 11, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When trying to build .Net 7 (Angular and WebAPI )application we are getting

`13>Method "get_ServerSideSessions" in type "Microsoft.AspNetCore.ApiAuthorization.IdentityServer.ApiAuthorizationDbContext"1" from assembly "Microsoft.AspNetCore.ApiAuthorization.IdentityServer, Version=7.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" does not have an implementation.)

13> ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
13>Method "get_ServerSideSessions" in type "Microsoft.AspNetCore.ApiAuthorization.IdentityServer.ApiAuthorizationDbContext"1" from assembly "Microsoft.AspNetCore.ApiAuthorization.IdentityServer, Version=7.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" does not have an implementation.

13> at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
13> at Microsoft.AspNetCore.Mvc.Controllers.ControllerFeatureProvider.PopulateFeature(IEnumerable"1 parts, ControllerFeature feature)
13> at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature)
13> at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetControllerTypes()
13> at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetDescriptors()
13> at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
13> at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection()
13> at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.Initialize()
13> at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.GetChangeToken()
13> at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func"1 changeTokenProducer, Action changeTokenConsumer)
13> at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.Subscribe()
13> at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.GetOrCreateDataSource(IEndpointRouteBuilder endpoints)
13> at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllerRoute(IEndpointRouteBuilder endpoints, String name, String pattern, Object defaults, Object constraints, Object dataTokens)
13> at HomePlanner.Server.Application.Program.Main(String[] args) in D:\PROJEKTY\HomePlanner\HomePlanner.Server\HomePlanner.Server.Application\Program.cs:line 57
13> at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
13> at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
13>System.TypeLoadException: Method "get_ServerSideSessions" in type "Microsoft.AspNetCore.ApiAuthorization.IdentityServer.ApiAuthorizationDbContext"1" from assembly "Microsoft.AspNetCore.ApiAuthorization.IdentityServer, Version=7.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" does not have an implementation.
13> --- End of inner exception stack trace ---
13> at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
13> at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
13> at System.Threading.Tasks.Task.Wait()
13> at NSwag.Commands.ServiceProviderResolver.GetServiceProviderWithHostFactoryResolver(Assembly assembly) in //src/NSwag.Commands/HostApplication.cs:line 158
13> at NSwag.Commands.ServiceProviderResolver.GetServiceProvider(Assembly assembly) in /
/src/NSwag.Commands/HostApplication.cs:line 70
13> at NSwag.Commands.Generation.AspNetCore.AspNetCoreToOpenApiGeneratorCommandEntryPoint.Process(String commandContent, String outputFile, String applicationName) in //src/NSwag.Commands/Commands/Generation/AspNetCore/AspNetCoreToOpenApiGeneratorCommandEntryPoint.cs:line 27
13> at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
13> at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
13> --- End of inner exception stack trace ---
13> at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
13> at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
13> at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
13> at NSwag.AspNetCore.Launcher.Program.Main(String[] args) in /
/src/NSwag.AspNetCore.Launcher/Program.cs:line 132
13>System.InvalidOperationException: Swagger generation failed with non-zero exit code "1".
13> at NSwag.Commands.Generation.AspNetCore.AspNetCoreToSwaggerCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in //src/NSwag.Commands/Commands/Generation/AspNetCore/AspNetCoreToOpenApiCommand.cs:line 231
13> at NSwag.Commands.NSwagDocumentBase.GenerateSwaggerDocumentAsync() in /
/src/NSwag.Commands/NSwagDocumentBase.cs:line 275
13> at NSwag.Commands.NSwagDocument.ExecuteAsync() in //src/NSwag.Commands/NSwagDocument.cs:line 81
13> at NSwag.Commands.Document.ExecuteDocumentCommand.ExecuteDocumentAsync(IConsoleHost host, String filePath) in /
/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 85
13> at NSwag.Commands.Document.ExecuteDocumentCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in //src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 39
13> at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
13> at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
13> at NSwag.Commands.NSwagCommandProcessor.ProcessAsync(String[] args) in /
/src/NSwag.Commands/NSwagCommandProcessor.cs:line 61`

We are using the latest versions of the packages (there is nothing to update)

<PackageReference Include="AutoMapper" Version="12.0.0" />
<PackageReference Include="AutoMapper.Collection" Version="9.0.0" />
<PackageReference Include="AutoMapper.Collection.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="6.0.2" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />

<PackageReference Include="Duende.IdentityServer" Version="6.2.0" />
<PackageReference Include="Duende.IdentityServer.AspNetIdentity" Version="6.2.0" />
<PackageReference Include="Duende.IdentityServer.EntityFramework" Version="6.2.0" />
<PackageReference Include="Duende.IdentityServer.Storage" Version="6.2.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.4.0" />     

<PackageReference Include="Microsoft.AspNetCore.ApiAuthorization.IdentityServer" Version="7.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="7.0.2" />
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2"/> 
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />  
...

We created this issue because previous one was not updated in laset two months (#44990 and its PR !45145)

Current state of Microsoft.AspNetCore.ApiAuthorization.IdentityServer package is blocking upgrade to .Net 7 IdentityServer 6.2

As was pointed out .Net 7 needs AutoMapper 12 (1), newest IndentityServer (6.2.0) also has supports .Net 7 and uses AutoMapper 12 but at the same time they added that ServerSideSessions DbSet (2) which is not present in ApiAuthorizationDbContext of Microsoft.AspNetCore.ApiAuthorization.IdentityServer 7.0.0 (3)

I have tried to lower the versions of Duende.IdentityServer to 6.0.4 which is last version without ServerSideSessions but then I have to lower version of AutoMapper to 11 and that results in error ("violates the constraint of type parameter 'T'" (1)).

  1. MaxInteger[T](System.Collections.Generic.IEnumerable`1[T])' violates the constraint of type parameter 'T' exception AutoMapper/AutoMapper#3988
    [dotnet-sdk-7.0.100-preview.5.22257.3] MaxInteger[T](System.Collections.Generic.IEnumerable`1[T])' violates the constraint of type parameter 'T' exception error runtime#69119
  2. https://docs.duendesoftware.com/identityserver/v6/data/operational/sessions/
  3. ApiAuthorizationDbContext.cs missing ServerSideSessions Patch #45145

Expected Behavior

Application should build.
Method get_ServerSideSessions in type ApiAuthorizationDbContext from assembly IdentityServer does not have an implementation error should disappear

Steps To Reproduce

Create application that uses
Duende.IdentityServer (and related) 6.2.0
Microsoft.AspNetCore.ApiAuthorization.IdentityServer (and related) 7.0.2
AutoMapper (and related) 12.0.0

Exceptions (if any)

No response

.NET Version

7.0

Anything else?

No response

@javiercn
Copy link
Member

@Alan468 thanks for contacting us.

Thanks for bringing this up to our attention. It fell out of our radar likely due to the holidays.

I took another chance to look at this and better understand what is going on, so here is a more detailed explanation of what is happening.

There is a way to make it work with the following steps:

  • Remove the usage of ApiAuthorizationDbContext from the app:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>, IPersistedGrantDbContext {

    private readonly IOptions<OperationalStoreOptions> _operationalStoreOptions;

    public ApplicationDbContext(
        DbContextOptions options,
        IOptions<OperationalStoreOptions> operationalStoreOptions)
        : base(options) {
        _operationalStoreOptions = operationalStoreOptions;
    }

    public DbSet<PersistedGrant> PersistedGrants { get; set; }

    public DbSet<DeviceFlowCodes> DeviceFlowCodes { get; set; }

    public DbSet<Key> Keys { get; set; }

    public DbSet<ServerSideSession> ServerSideSessions { get; set; }

    Task<int> IPersistedGrantDbContext.SaveChangesAsync() => base.SaveChangesAsync();

    protected override void OnModelCreating(ModelBuilder builder) {
        base.OnModelCreating(builder);
        builder.ConfigurePersistedGrantContext(_operationalStoreOptions.Value);
    }
}
  • Remove the assembly from the list of application parts:
builder.Services.AddControllersWithViews()
    .ConfigureApplicationPartManager(apm => {
        apm.ApplicationParts
        .Remove(apm.ApplicationParts.Single(ap => ap.Name == "Microsoft.AspNetCore.ApiAuthorization.IdentityServer"));
    });
  • You might need to add or recreate the migrations.

The breaking change is located in Duende.IdentityServer.EntityFramework.Storage.

Unfortunately, I do not think we can't do anything about this out of the box, since we can't change the public API in patch releases, but I am asking if there is an exception that can be made.

I would suggest in parallel raising this issue with the Identity Server team, as they might have a way to revert the breaking change in a future release and delay it until a major version. That would make future versions compatible with our package again.

@javiercn javiercn added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Jan 11, 2023
@ghost
Copy link

ghost commented Jan 11, 2023

Hi @Alan468. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@MichelJansson
Copy link
Contributor

@javiercn, Thanks for getting back to us. I believe the root-cause of this issue was that MS unfortunately opted to keep using the old Identity Server package even though it existed multiple reported issues around this well before the NET 7 release.

As for the workaround; The last missing piece of the puzzle from our previous endeavors was removing the application part. Doing that and the server now fires right up.
What does it do exactly? Is there any implications other than it not finding the ApiAuthorizationDbContext?

@javiercn
Copy link
Member

What does it do exactly? Is there any implications other than it not finding the ApiAuthorizationDbContext?

There are no other implications since that assembly does not contain controllers or razor pages.

@Alan468
Copy link
Author

Alan468 commented Jan 12, 2023

Thank you @javiercn for quick response - I can also confirm that this workaround works and application starts correctly.
As per seperate ticket for Duende Identity Server - I have created it for more info on the topic (DuendeArchive/Support#445)

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Jan 12, 2023
@javiercn javiercn added question ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Jan 12, 2023
@ghost ghost added the Status: Resolved label Jan 12, 2023
@ghost
Copy link

ghost commented Jan 13, 2023

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed Jan 13, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Feb 12, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-spa ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants