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

相关推荐
缺点内向20 小时前
C#: 告别繁琐!轻松移除Word文档中的文本与图片水印
c#·自动化·word·.net
2501_9307077821 小时前
使用 C# .NET 从 PowerPoint 演示文稿中提取背景图片
c#·powerpoint·.net
向上的车轮1 天前
为什么.NET(C#)转 Java 开发时常常在“吐槽”Java:checked exception
java·c#·.net
波波0071 天前
每日一题:.NET 的 GC是如何分代工作的?
算法·.net·gc
波波0072 天前
每日一题:中间件是如何工作的?
中间件·.net·面试题
无风听海2 天前
.NET 10之可空引用类型
数据结构·.net
码云数智-园园2 天前
基于 JSON 配置的 .NET 桌面应用自动更新实现指南
.net
无风听海2 天前
.NET 10 之dotnet run的功能
.net
岩屿2 天前
Ubuntu下安装Docker并部署.NET API(二)
运维·docker·容器·.net
码云数智-大飞2 天前
.NET 中高效实现 List 集合去重的多种方法详解
.net