openiddict / openiddict-core

Flexible and versatile OAuth 2.0/OpenID Connect stack for .NET
https://openiddict.com/
Apache License 2.0
4.46k stars 525 forks source link

ApplicationManager->ListAsync doesn't work after upgrading MongoDriver to 2.21 from 2.18 #1861

Closed Nfactor26 closed 1 year ago

Nfactor26 commented 1 year ago

Confirm you've already contributed to this project or that you sponsor it

Version

4.x

Question

Description I am trying to upgrade OpenIdDict binaries for https://github.com/Nfactor26/pixel-identity to version 4.7. This requires me to also update MongoDB.Driver to a newer version [OpenIddict.MongoDb 4.7.0 -> MongoDB.Driver (>= 2.20.0)]. However, once I upgrade MondoDB.Driver to a newer version, ListAsync doesn't work anymore. This is not an issue with OpenIDDict but recent versions of Mongo driver . Please see issue https://jira.mongodb.org/browse/CSHARP-4535?attachmentOrder=desc .

Suggested Workaround Set LinqProvider = LinqProvider.V2 on MongoClientSettings as suggested on https://jira.mongodb.org/browse/CSHARP-4535?attachmentOrder=desc

Question Do we have any other workaround for OpenIddict.MongoDb 4.7.0 to get this working ?

Example Code

 Func<IQueryable<object>, IQueryable<OpenIddictMongoDbApplication>> query = (apps) =>
        {
            return apps.Where(app => true).Select(s => s as OpenIddictMongoDbApplication);
        };      
        await foreach (var app in applicationManager.ListAsync(query, CancellationToken.None))

https://github.com/Nfactor26/pixel-identity/blob/main/src/Pixel.Identity.Store.Mongo/Worker.cs

Exception System.ArgumentException: ValueType 'OpenIddict.MongoDb.Models.OpenIddictMongoDbApplication' of parameterSerializer does not match parameter type 'System.Object'. (Parameter 'parameterSerializer') at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ExpressionToFilterTranslator.TranslateLambda(TranslationContext context, LambdaExpression lambdaExpression, IBsonSerializer parameterSerializer, Boolean asRoot) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.WhereMethodToPipelineTranslator.Translate(TranslationContext context, MethodCallExpression expression) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.ExpressionToPipelineTranslator.Translate(TranslationContext context, Expression expression) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.SelectMethodToPipelineTranslator.Translate(TranslationContext context, MethodCallExpression expression) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.ExpressionToPipelineTranslator.Translate(TranslationContext context, Expression expression) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToExecutableQueryTranslators.ExpressionToExecutableQueryTranslator.Translate[TDocument,TOutput](MongoQueryProvider1 provider, Expression expression) at MongoDB.Driver.Linq.Linq3Implementation.MongoQuery2.ToCursorAsync(CancellationToken cancellationToken) at MongoDB.Driver.OpenIddictMongoDbHelpers.<ToAsyncEnumerable>g__ExecuteAsync|0_0[T](IAsyncCursorSource1 source, CancellationToken cancellationToken)+MoveNext() at MongoDB.Driver.OpenIddictMongoDbHelpers.gExecuteAsync|0_0[T](IAsyncCursorSource1 source, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at OpenIddict.MongoDb.OpenIddictMongoDbApplicationStore1.<>c__DisplayClass30_0`2.<gExecuteAsync|0>d.MoveNext() --- End of stack trace from previous location --- at OpenIddict.MongoDb.OpenIddictMongoDbApplicationStore1.<>c__DisplayClass30_02.<gExecuteAsync|0>d.MoveNext() --- End of stack trace from previous location --- at OpenIddict.MongoDb.OpenIddictMongoDbApplicationStore`1.<>cDisplayClass30_02.<<ListAsync>g__ExecuteAsync|0>d.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult(Int16 token) at Pixel.Identity.Store.Mongo.Worker.StartAsync(CancellationToken cancellationToken) in F:\Git\Pixel.Identity\src\Pixel.Identity.Store.Mongo\Worker.cs:line 145

Disclaimer I am not a direct contributor to this project but maintain another helper project (https://github.com/Nfactor26/pixel-identity) on top of OpenIDDict to provide a UI for it.

kevinchalet commented 1 year ago

Hey,

Thanks for the report. Per our discussion on Gitter, I updated the 4.7.0 release notes (https://github.com/openiddict/openiddict-core/releases/tag/4.7.0) to include the recommended workaround.

Cheers.