尝试从适配器 'NetCoreContainerAdapter' 解析服务 'System.Boolean' 时出错

Error trying to resolve Service 'System.Boolean' from Adapter 'NetCoreContainerAdapter'

最近转换为 .NET Core 后,我在尝试使用我们的任何 AuthProvider 进行身份验证时收到以下错误:

“尝试从适配器 'NetCoreContainerAdapter' 解析服务 'System.Boolean' 时出错:对象引用未设置为对象的实例。”

我在 .NET Core 3.1 上使用 ServiceStack.Core 5.9.2。

堆栈跟踪

   at Funq.Container.GetEntry[TService,TFunc](String serviceName, Boolean throwIfMissing) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Funq\Container.cs:line 490
   at Funq.Container.ResolveImpl[TService](String name, Boolean throwIfMissing) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Funq\Container.cs:line 183
   at Funq.Container.TryResolveNamed[TService](String name) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Funq\Container.Overloads.cs:line 389
   at Funq.Container.TryResolve[TService]() in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Funq\Container.Overloads.cs:line 336
   at Funq.Container.<>c__DisplayClass16_0`4.<ReverseLazyResolve>b__1(TArg1 a1, TArg2 a2, TArg3 a3) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Funq\Container.Adapter.cs:line 125
   at ServiceStack.Auth.AuthProvider.IsAccountLocked(IAuthRepository authRepo, IUserAuth userAuth, IAuthTokens tokens) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Auth\AuthProvider.cs:line 359
   at Authentication.AuthUtilities.HandleSuccessfulTryAuthenticate(CredentialsAuthProvider authProvider, IServiceBase authService, User user, IDbConnection db) in AuthUtilities.cs:line 100
   at Authentication.AuthProviders.SgCredentialsAuthProvider.TryAuthenticate(IServiceBase authService, String userName, String password) in SGCredentialsAuthProvider.cs:line 31
   at ServiceStack.Auth.CredentialsAuthProvider.Authenticate(IServiceBase authService, IAuthSession session, String userName, String password, String referrerUrl) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Auth\CredentialsAuthProvider.cs:line 120
   at ServiceStack.Auth.CredentialsAuthProvider.Authenticate(IServiceBase authService, IAuthSession session, Authenticate request) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Auth\CredentialsAuthProvider.cs:line 98
   at ServiceStack.Auth.AuthenticateService.Authenticate(Authenticate request, String provider, IAuthSession session, IAuthProvider oAuthConfig) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Auth\AuthenticateService.cs:line 413
   at ServiceStack.Auth.AuthenticateService.Post(Authenticate request) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Auth\AuthenticateService.cs:line 218

SgCredentialsAuthProvider 在国际奥委会注册了吗?它只能作为 AuthProvider 添加到您的 AuthFeature 插件注册中。

该错误表明您有一个 autowired 服务或具有 public bool 属性 的依赖项或正在尝试的构造函数注入了从 IsAccountLocked() method:

调用的不存在的 bool 依赖项
public virtual bool IsAccountLocked(IAuthRepository authRepo, IUserAuth userAuth, IAuthTokens tokens=null)
{
    if (AccountLockedValidator != null)
        return AccountLockedValidator(authRepo, userAuth, tokens);
    
    return userAuth?.LockedDate != null;
}

从其实施来看,国际奥委会正试图从国际奥委会解决 AccountLockedValidator 的每个通用参数,但在 bool 通用参数上失败:

public Func<IAuthRepository, IUserAuth, IAuthTokens, bool> AccountLockedValidator { get; set; }

删除您的 SgCredentialsAuthProvider 的 IOC 注册,或者如果您正在执行一些自动扫描/自动连接依赖项则忽略它应该可以解决它。