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

ASP.NET Core 6.0本地正常,部署Azure Web App遇BadImageFormatException

部署生产环境后出现反射加载类型错误

更新1: 添加发布配置截图

我创建了一个新项目,本地调试运行正常,但部署到生产环境后持续出现以下错误:

System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.  Could not load file or assembly 'SDKServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. An attempt was made to load a program with an incorrect format.
     at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
     at System.Reflection.RuntimeAssembly.get_DefinedTypes()
     at Microsoft.AspNetCore.Mvc.ApplicationParts.AssemblyPart.get_Types()
     at Microsoft.AspNetCore.Mvc.Controllers.ControllerFeatureProvider.PopulateFeature(IEnumerable`1 parts, ControllerFeature feature)
     at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature)
     at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetControllerTypes()
     at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetDescriptors()
     at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
     at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection()
     at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.Initialize()
     at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.<>c__DisplayClass11_0.<Subscribe>b__0()
     at Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration`1..ctor(Func`1 changeTokenProducer, Action`1 changeTokenConsumer, TState state)     at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer)     at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.Subscribe()     at Microsoft.AspNetCore.Mvc.Routing.ControllerActionEndpointDataSource..ctor(ControllerActionEndpointDataSourceIdProvider dataSourceIdProvider, IActionDescriptorCollectionProvider actions, ActionEndpointFactory endpointFactory, OrderedEndpointsSequenceProvider orderSequence)     at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.GetOrCreateDataSource(IEndpointRouteBuilder endpoints)     at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllers(IEndpointRouteBuilder endpoints)
     at Project.Program.Main(String[] args) in C:\Users\user\path\Project\Program.cs:line 65  System.BadImageFormatException: Could not load file or assembly 'SDKServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. An attempt was made to load a program with an incorrect format.  File name: 'SDKServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

已尝试的解决方案:

  • 完整重建项目并重新部署
  • 确保主项目及所有依赖项目的目标平台一致,均设置为Any CPU
  • 发布目标设为win-x86,同时将Web App的配置(WebApp | 配置 | 常规设置)中的“平台”改为32位
  • 通过Kudu控制台删除多数*.dll文件后重新上传(无权限删除全部文件)

项目配置

  • 框架版本:ASP.NET Core 6.0
  • 依赖库列表:
    • Microsoft.Data.SqlClient Version="5.1.2"
    • NLog Version="5.2.5"
    • NLog.Database Version="5.2.5"
    • NLog.Extensions.Logging Version="5.2.5"
    • NLog.Web.AspNetCore Version="5.2.3"
    • Swashbuckle.AspNetCore Version="6.5.0"

发布配置截图

发布配置截图

目前所有尝试的方案均未解决问题,错误仍持续发生,且错误触发点为Program.cs的Main方法中调用app.MapControllers()时。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 18:52:32