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

.NET Framework 4.8升级SimpleInjector 5.5.0后程序集加载失败求助

.NET Framework 4.8项目升级SimpleInjector 5.5.0后程序集加载失败

我有一个基于.NET Framework 4.8的多项目解决方案,其中部分项目依赖SimpleInjector库。近期将所有SimpleInjector相关包更新至最新版本5.5.0后,运行项目时抛出异常:无法加载文件或程序集'SimpleInjector'或其依赖项。

已执行的排查操作

  • 手动检查解决方案内所有项目,确认所有引用SimpleInjector的项目均已更新至5.5.0版本
  • 修改Web.config文件,添加/更新程序集绑定重定向配置:
<dependentAssembly>
  <assemblyIdentity name="SimpleInjector" publicKeyToken="984cb50dea722e99" culture="neutral"/>
  <bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0"/>
</dependentAssembly>

当前已安装的相关包

解决方案中已安装的SimpleInjector系列包版本均为5.5.0,包括:

  • SimpleInjector
  • SimpleInjector.Integration.Mvc
  • SimpleInjector.Integration.WebApi

Global.asax核心代码

// 创建容器实例
var container = new Container();
container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

// 配置依赖注入
DependencyInjectionConfiguration.Configure(container);

// 注册Mvc控制器(集成包扩展方法)
container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

// 配置对象映射(需最后执行,因为会创建实例)
ConfigureMappers(container);

// 设置Mvc和WebApi的依赖解析器
DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);

// 验证容器配置
container.Verify();

尝试的调试操作

为定位问题,在Global.asax中添加了以下代码强制加载程序集类型,但调试时依然报错:

var assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in assemblies)
{
    try
    {
        var types = assembly.GetTypes(); // 强制加载程序集内的类型
    }
    catch (ReflectionTypeLoadException ex)
    {
        foreach (var loaderException in ex.LoaderExceptions)
        {
            Console.WriteLine($"Assembly: {assembly.FullName} - Error: {loaderException.Message}");
        }
    }
}

内容的提问来源于stack exchange,提问作者mnu-nasir

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 18:35:09