项目升级到.Net8.0 Autofac引发诡异的问题

前两天把项目升级到.Net8.0了,把.Net框架升级了,其他一些第三方库升级了一部分,升级完以后项目跑不起来了,报如下错误:

复制代码
An unhandled exception occurred while processing the request.
DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Microsoft.AspNetCore.Mvc.ApiExplorer.EndpointMetadataApiDescriptionProvider' can be invoked with the available services and parameters:
Cannot resolve parameter 'Microsoft.Extensions.DependencyInjection.IServiceProviderIsService serviceProviderIsService' of constructor 'Void .ctor(Microsoft.AspNetCore.Routing.EndpointDataSource, Microsoft.Extensions.Hosting.IHostEnvironment, Microsoft.AspNetCore.Routing.ParameterPolicyFactory, Microsoft.Extensions.DependencyInjection.IServiceProviderIsService)'.
Autofac.Core.Activators.Reflection.ReflectionActivator.GetAllBindings(ConstructorBinder[] availableConstructors, IComponentContext context, IEnumerable<Parameter> parameters)

DependencyResolutionException: An exception was thrown while activating Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator -> Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider -> λ:Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionProvider[] -> Microsoft.AspNetCore.Mvc.ApiExplorer.EndpointMetadataApiDescriptionProvider.

看着是依赖注入的问题,后面去网上找了一下,找到博客园的一篇文章,提到是vs版本的问题,我现在用的vs版本是17.11.5,看完以后心里想vs应该不会和影响到代码,我想着通过命令行 dotnet xxx.dll 能不能启动,奇怪了命令行可以启动;接着我又用vscode试了一下,也可以启动,这就很奇怪了。

我把项目.Net6.0的代码签出项目可以跑起来,看来还是升级的问题,和依赖注入有关,后面想到了可能是autofac没有升级,把autofac升级到10.0就没问题了。

问题虽然解决了,但还是很纳闷,怎么不升级autofac,vs会导致项目跑不起来了,但是通过命令行和vscode又可以。

相关推荐
light blue bird5 小时前
工序 BOM 协同系统架构多模块组件
数据库·信息可视化·.net
学以智用6 小时前
.NET Core 序列化 **超清晰完整版教程**
后端·.net
周杰伦fans7 小时前
AutoCAD .NET 二次开发:深入理解 ObjectId = 0 与 ObjectId.Null
数据库·oracle·.net
半亩码田8 小时前
【.NET新特性·第4篇】.NET Aspire 入门:云原生开发新姿势
云原生·.net
步步为营DotNet9 小时前
洞悉.NET 11:ASP.NET Core 10 在构建实时协作 Web 应用的技术实践
前端·asp.net·.net
2601_961194029 小时前
27考研刘晓燕资源
linux·sql·ubuntu·华为·pdf·.net
light blue bird1 天前
支组汇总主子节点工序路径图表
前端·jvm·.net·桌面端·gdi绘图
bugcome_com1 天前
阿里云OSS工具类完整设计与实现:基于.NET的静态单例模式实践
阿里云·单例模式·.net·oss
步步为营DotNet1 天前
深度剖析.NET 11:Microsoft.Extensions.AI 在智能后端决策系统的创新应用 前言
人工智能·microsoft·.net
无风听海2 天前
ASP.NET Core .NET 10 错误响应体系全景:从 BadRequest 到编译器基础设施
后端·asp.net·.net