/.well-known/openid-configurationSystem.NotImplementedException occurs in Microsoft.EntityFrameworkCore as result of IdentityServer4.EntityFramework.Services.CorsPolicyService.IsOriginAllowedAsync call.[17:26:22 INF] Request starting HTTP/2 GET https://localhost:5011/.well-known/openid-configuration
[17:26:22 INF] CORS policy execution successful.
[17:26:23 ERR] An unhandled exception has occurred while executing the request.
System.NotImplementedException: The method or operation is not implemented.
at ShapedQueryExpression Microsoft.EntityFrameworkCore.Relational.Query.Pipeline.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateSelectMany(ShapedQueryExpression source, LambdaExpression selector)
at Expression Microsoft.EntityFrameworkCore.Query.Pipeline.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Expression Microsoft.EntityFrameworkCore.Relational.Query.Pipeline.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Expression System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at Expression System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Expression Microsoft.EntityFrameworkCore.Query.Pipeline.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Expression Microsoft.EntityFrameworkCore.Relational.Query.Pipeline.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Expression System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at Expression System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Func<QueryContext, TResult> Microsoft.EntityFrameworkCore.Query.Pipeline.QueryCompilationContext.CreateQueryExecutor<TResult>(Expression query)
at Func<QueryContext, TResult> Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery<TResult>(Expression query, bool async)
at Func<QueryContext, TResult> Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore<TResult>(IDatabase database, Expression query, IModel model, bool async)
at TResult Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute<TResult>(Expression query)+() => { }
at Func<QueryContext, TFunc> Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore<TFunc>(object cacheKey, Func<Func<QueryContext, TFunc>> compiler)
at Func<QueryContext, TResult> Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery<TResult>(object cacheKey, Func<Func<QueryContext, TResult>> compiler)
at TResult Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute<TResult>(Expression query)
at TResult Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute<TResult>(Expression expression)
at IEnumerator<TResult> Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable<TResult>.GetEnumerator()
at new System.Collections.Generic.List<T>(IEnumerable<T> collection)
at List<TSource> System.Linq.Enumerable.ToList<TSource>(IEnumerable<TSource> source)
at Task<bool> IdentityServer4.EntityFramework.Services.CorsPolicyService.IsOriginAllowedAsync(string origin)
at void IdentityServer4.Stores.CachingCorsPolicyService<T>+<>c__DisplayClass6_0+<<IsOriginAllowedAsync>b__0>d.MoveNext()
at async Task<T> IdentityServer4.Extensions.ICacheExtensions.GetAsync<T>(ICache<T> cache, string key, TimeSpan duration, Func<Task<T>> get, ILogger logger)
at async Task<bool> IdentityServer4.Stores.CachingCorsPolicyService<T>.IsOriginAllowedAsync(string origin)
at async Task<CorsPolicy> IdentityServer4.Hosting.CorsPolicyProvider.ProcessAsync(HttpContext context)
at async Task Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.Invoke(HttpContext context, ICorsPolicyProvider corsPolicyProvider)+InvokeCoreAwaited(?)
at async Task IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
at async Task Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at async Task Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
at async Task Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
at async Task Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
at async Task Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
[17:26:23 INF] Request finished in 586.9837ms 500 text/plain
Hi @sandord
I also encountered this issue and I believe it could be due to aspnet/EntityFrameworkCore#16104.
The workaround for my solution involved downgrading the below packages to the below versions:
3.0.0-preview3.43.0.0-preview3.43.0.0-preview3.43.0.0-preview5-19227-013.0.0-preview5-19227-013.0.0-preview5.19227.13.0.0-preview5.19227.1The downgrading of any and all Entity Framework Core related packages to preview 5 is necessary due to the breaking changes that were introduced by the Entity Framework Core team in preview 6. Obviously your mileage using this workaround may vary and you may have to downgrade additional packages.
Thanks, I've now downgraded to preview 5 as well. At least that one works. Now let's hope they fix that EF issue anytime soon.
Yes, all the ASP.NET Core and EF 3 related issues we'd encountered have been submitted to Microsoft. We're told that most of them are already fixed, but not yet released.
This can also be temporarily worked around without downgrading by implementing a custom CorsPolicyService that changes the way the query is constructed:
using System;
using System.Linq;
using System.Threading.Tasks;
using IdentityServer4.EntityFramework.Interfaces;
using IdentityServer4.EntityFramework.Services;
using IdentityServer4.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace MyNamespace {
/// <summary>
/// Implementation of ICorsPolicyService that consults the client configuration in the database for allowed CORS origins.
/// </summary>
/// <seealso cref="IdentityServer4.Services.ICorsPolicyService" />
public class IdentityServerCorsPolicyService : ICorsPolicyService {
private readonly IHttpContextAccessor _context;
private readonly ILogger<CorsPolicyService> _logger;
/// <summary>
/// Initializes a new instance of the <see cref="CorsPolicyService"/> class.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="logger">The logger.</param>
/// <exception cref="ArgumentNullException">context</exception>
public IdentityServerCorsPolicyService(IHttpContextAccessor context, ILogger<CorsPolicyService> logger) {
_context = context ?? throw new ArgumentNullException(nameof(context));
_logger = logger;
}
/// <summary>
/// Determines whether origin is allowed.
/// </summary>
/// <param name="origin">The origin.</param>
/// <returns></returns>
public Task<bool> IsOriginAllowedAsync(string origin) {
// doing this here and not in the ctor because: https://github.com/aspnet/CORS/issues/105
var dbContext = _context.HttpContext.RequestServices.GetRequiredService<IConfigurationDbContext>();
var origins =
dbContext.Clients
.Include(c => c.AllowedCorsOrigins)
.AsNoTracking()
.AsEnumerable()
.SelectMany(x => x.AllowedCorsOrigins.Select(y => y.Origin)).ToList();
var distinctOrigins = origins.Where(x => x != null).Distinct();
var isAllowed = distinctOrigins.Contains(origin, StringComparer.OrdinalIgnoreCase);
_logger.LogDebug("Origin {origin} is allowed: {originAllowed}", origin, isAllowed);
return Task.FromResult(isAllowed);
}
}
}
This is identical to the built-in CorsPolicyService except for the LINQ bit. It results in a less efficient SQL query, since it will return a joined Client - AllowedCorsOrigin -dataset, but it works.
Will be taken care of in the PR. thanks!
Apparently, it hasn't been fixed yet in EntityFrameworkCore Preview 9. https://github.com/aspnet/EntityFrameworkCore/issues/16104#issuecomment-529953265
yea, we noticed. we changed how our cors service queries the DB to work around it. did you try our 3.0.0 build?
Hi @brockallen, I can confirm that everything is now working as intended after upgrading all of my packages to their latest versions. See here for my changes. Many thanks for resolving the issue.
Works here as well. Thanks!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Yes, all the ASP.NET Core and EF 3 related issues we'd encountered have been submitted to Microsoft. We're told that most of them are already fixed, but not yet released.