项目升级到.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又可以。

相关推荐
SEO-狼术6 小时前
FastReport .NET Mono 2026
.net
赵庆明老师8 小时前
.Net 中使用HttpClient 调用SOAP 服务
.net
用户2986985301412 小时前
C# 中如何从 URL 下载 Word 文档:基于 Spire.Doc 的高效解决方案
后端·c#·.net
喵叔哟15 小时前
65.【.NET8 实战--孢子记账--从单体到微服务--转向微服务】--新增功能--账本合并
.net
波波00715 小时前
使用.NET 四步玩转 AI 绘图|不用Python、不买显卡
开发语言·c#·.net
唐青枫16 小时前
深入理解 C#.NET 运算符重载:语法、设计原则与最佳实践
c#·.net
用户4488466710601 天前
.NET进阶——深入理解Lambda表达式(2)手搓LINQ语句
c#·.net
步步为营DotNet2 天前
深度探究Span:.NET内存布局与零拷贝原理及实践
.net
专注VB编程开发20年2 天前
多线程解压安装ZIP,EXE分析-微软的MSI安装包和 .NET SDK EXE
linux·运维·服务器·microsoft·.net
helloworddm2 天前
Orleans Grain Directory 详细解析
.net