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

Redis Set操作调用GetDatabase时触发Microsoft.Bcl.AsyncInterfaces加载异常

Redis Set操作时加载程序集异常问题

执行Redis的Set操作时原本正常,但运行IDatabase dbConnection = redisConnection.GetDatabase();时抛出如下异常:

System.IO.FileNotFoundException
  HResult=0x80070002
  Message=未能加载文件或程序集“Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51”或它的某一个依赖项。系统找不到指定的文件。
  Source=StackExchange.Redis
  StackTrace:
   at StackExchange.Redis.ConnectionMultiplexer.GetDatabase(Int32 db, Object asyncState) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 1420
   at RedisCache.CacheExtensions.SetRecord(String recordId, String data, Int32 minute) in RedisCache\CacheExtensions.cs:line 11
   at BusinessLogic.Services.Order.WebOrderService.SetOnlineOrderRedisCount(WebOrderGroup webOrderGroup) in BusinessLogic\Services\Order\WebOrderService.cs:line 2770
   at BusinessLogic.Services.Order.WebOrderService.SaveToMainTable(CurrentUserDetailedDTO currentUser, IUnitOfWork uow, AppClientIncomingJsonRequest jsonRequest, WebOrderGroup webOrderGroup) in BusinessLogic\Services\Order\WebOrderService.cs:line 2752
   at WebOrderService.ProcessOrder(WebOrderGroupDTO dto, CurrentUserDetailedDTO currentUser, String confirmEmailTemplatePath, String pendingReviewEmailTemplatePath, String prescriptionVerificationPendingEmailTemplatePath, RxRenewalEmailPathBrandWise rxRenewalEmailPathDto, String renewalOnlyEmailTemlplate) in BusinessLogic\Services\Order\WebOrderService.cs:line 6347
   at Api.Controllers.Order.OrderController.ProcessWebOrder(WebOrderGroupDTO dto) in Api\Controllers\Order\OrderController.cs:line 812
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

Inner Exception 1:
FileNotFoundException: 未能加载文件或程序集“Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51”或它的某一个依赖项。系统找不到指定的文件。

相关代码

实现于类库中,供业务逻辑层调用:

public static void SetRecord(string recordId, string data, int minute = 30)
{
    var redisConnection = Common.RedisCacheServiceClient();
    IDatabase dbConnection = redisConnection.GetDatabase();

    var timeSpan = TimeSpan.FromMinutes(minute);
    dbConnection.StringSet(recordId, data, timeSpan);
}

版本信息

  • StackExchange.Redis:2.1.58
  • Microsoft.Bcl.AsyncInterfaces:1.1.1

所有项目均基于Microsoft.Bcl.AsyncInterfaces 1.1.1开发,选择StackExchange.Redis 2.1.58是为了保证版本兼容性。

Redis类库的App.config配置

<dependentAssembly>
    <assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
</dependentAssembly>

解决方法

  1. 修正程序集绑定重定向配置
    当前绑定重定向把旧版本指向了1.0.0.0,但实际使用的是1.1.1版本,需要修改配置,将newVersion改为1.1.1.0,同时调整oldVersion范围覆盖到6.0.0.0(异常中提到了要加载该版本):

    <dependentAssembly>
        <assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="1.1.1.0" />
    </dependentAssembly>
    

    注意:这个配置必须放在启动项目的App.config/Web.config里,类库的配置文件不会单独生效,程序集绑定重定向由入口程序加载时解析。

  2. 确认NuGet包安装情况
    检查所有项目(尤其是启动项目)是否都正确安装了Microsoft.Bcl.AsyncInterfaces 1.1.1包,排查是否有其他项目引用更高版本包导致冲突。

  3. 清理并重新生成解决方案

    • 删除所有项目的bin和obj文件夹
    • 执行“清理解决方案”后再“重新生成解决方案”
    • 确认启动项目的输出目录中存在Microsoft.Bcl.AsyncInterfaces.dll文件
  4. 验证StackExchange.Redis依赖兼容性
    确认StackExchange.Redis 2.1.58对Microsoft.Bcl.AsyncInterfaces的依赖范围是否允许使用1.1.1版本,若存在强制版本要求,需调整对应包版本。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.23 09:54:17