You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行时加载Microsoft.Extensions.Logging.Abstractions程序集失败求助

解决无法加载'Microsoft.Extensions.Logging.Abstractions'程序集的问题

针对你遇到的程序集加载错误,尝试以下排查步骤:

  • 统一NuGet包版本
    Azure Functions对依赖版本一致性要求严格,打开NuGet包管理器,检查Microsoft.Extensions.Logging.Abstractions、Microsoft.EntityFrameworkCore.SqlServer、Microsoft.Azure.Functions.Extensions等相关包的版本,确保所有包对齐到同一大版本(比如Functions v4对应.NET 6/7/8,相关包使用6.x/7.x/8.x版本),避免跨版本依赖冲突。

  • 清理重建项目

    1. 删除项目根目录下的bin和obj文件夹
    2. 在Visual Studio中执行Build -> Clean Solution,再执行Build -> Rebuild Solution
    3. 清除NuGet本地缓存:运行命令dotnet nuget locals all --clear,或在NuGet包管理器设置中手动清空
  • 优化Startup配置代码
    将AddDbContext的写法简化为常规扩展方法调用,避免潜在版本兼容问题:

    builder.Services.AddDbContext<ApplicationDbContext>(
      options => options.UseSqlServer(connectionString));
    

    同时确认ApplicationDbContext的构造函数正确接收DbContextOptions<ApplicationDbContext>参数:

    public class ApplicationDbContext : DbContext
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
        {
        }
        // 你的DbSet和其他配置
    }
    
  • 检查Functions运行时版本
    打开项目的local.settings.json,确保FUNCTIONS_EXTENSION_VERSION设置正确,比如v4版本对应.NET 6+:

    {
      "IsEncrypted": false,
      "Values": {
        "FUNCTIONS_EXTENSION_VERSION": "~4",
        // 其他配置项
      }
    }
    
  • 重装相关NuGet包
    先卸载Microsoft.Extensions.Logging.Abstractions、Microsoft.EntityFrameworkCore.SqlServer、Microsoft.Azure.Functions.Extensions这些包,再重新安装对应版本的包,确保安装过程无报错。


原问题中的Startup代码:

[assembly: FunctionsStartup(typeof(HiQFoodCourt.Functions.StartUp))]

namespace HiQFoodCourt.Functions
{
    public class StartUp : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            string connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            
            builder.Services.AddDbContext<ApplicationDbContext>(
              options => SqlServerDbContextOptionsExtensions.UseSqlServer(options, connectionString));

            var mapperConfig = new MapperConfiguration(x =>
            {
                x.AddProfile(new MappingProfile());
            });

            IMapper mapper = mapperConfig.CreateMapper();
            builder.Services.AddSingleton(mapper);
        }
    }
}

错误截图:
无法加载Microsoft.Extensions.Logging.Abstractions错误截图

内容的提问来源于stack exchange,提问作者LordAhune

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 06:30:47