错误
提示:Some services are not able to be constructed (Error while validating the service descriptor ‘ServiceType: Microsoft.AspNetCore.Session.ISessionStore Lifetime: Transient ImplementationType: Microsoft.AspNetCore.Session.DistributedSessionStore’: Unable to resolve service for type ‘Microsoft.Extensions.Caching.Distributed.IDistributedCache’ while attempting to activate ‘Microsoft.AspNetCore.Session.DistributedSessionStore’.)

翻译
无法构造某些服务(验证服务描述符“ServiceType:Microsoft.AspNetCore.Session.ISessionStore生存期:瞬态实现类型:Microsoft.AspNetCore.Session.DistributedSessionStore”时出错):无法解析类型“Microsoft.Extensions.Caching.DistributedCache”的服务,而正在尝试激活“Microsoft.AspNetCore.Session.DistributedSessionStore”。)
解决办法
具体原因不是很清楚(有时间再去了解细节),看到 ”无法解析类型“Microsoft.Extensions.Caching.DistributedCache”的服务“,猜测需要添加 DistributedCache 服务,于是在 ConfigureServices 添加了
services.AddDistributedMemoryCache();
再次运行就好了。

在启用.NET Core 3.1应用的Session服务后,遇到构造服务时的错误,提示无法解析IDistributedCache服务。错误详细信息涉及到DistributedSessionStore的激活问题。解决方法是在ConfigureServices方法中添加DistributedMemoryCache服务,从而解决IDistributedCache服务的依赖问题,应用运行正常。
86

被折叠的 条评论
为什么被折叠?



