c# - .Net Core 2.0 内部服务器错误与 Redis 缓存

标签 c# asp.net-core redis

我正在尝试向我的 .Net Core 2.0 应用程序添加 Redis 缓存支持,但在发布到 Azure 应用服务后遇到问题。

我已经在 appsetting.json 中为我的 Azure Redis 缓存指定了连接字符串,将所需的位添加到 Startup.cs 并测试了在本地成功存储和检索数据。

应用程序发布后,启动失败,只报告启动应用程序时出现问题。

Startup.cs 中似乎导致问题的行是:

services.AddDistributedRedisCache(o => { o.Configuration = redisConnection; });

字符串“redisConnection”在上面使用:

string redisConnection = Configuration.GetConnectionString("Redis");

我不确定为什么只有在发布时才会失败。 如何调试失败原因?

编辑: 我已经设法解决了这个错误,指的是正在使用的 Microsoft.Extensions.Caching.Redis 的版​​本。

FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Caching.Redis, Version=2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Bootstrap_CoreApp.Startup.ConfigureServices(IServiceCollection services) System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services) Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices() Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

我不确定为什么这是个问题,因为项目中引用的 NuGet 包设置为使用 2.0.1 版本

最佳答案

在我的例子中,我发现我向项目添加了两个 nuget 包:

  1. Microsoft.Extensions.Caching.Redis 版本 2.0.1
  2. Microsoft.Extensions.Caching.Redis.Core 版本 1.0.3

它在本地有效,但在 Azure 中无效。

然后我从项目中删除了 Microsoft.Extensions.Caching.Redis.Core,将项目部署到 Azure,网站启动没有任何问题。

关于c# - .Net Core 2.0 内部服务器错误与 Redis 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49325427/

相关文章:

c# - 重复类名上的 ASP.NET WebAPI 属性路由

c# - 无法配置 'IApplicationBuilder UseOwin'

redis - 为什么 Redis 在计算脚本的 SHA1 哈希之前要修剪尾随空格?

c# - Unity 3D 质量设置之间隐藏的差异?

c# - itext7 中的 htmlConverter 在我希望它在 C# 中关闭之前关闭 pdf 文档

c# - Azure AD,无法针对邀请设置附加数据

c# - 宕机后如何发现redis up

java - SpringBoot Redis 远程主机

c# - 只有在等待返回的任务后才最终执行吗?

c# - 由于缺少 SSL 加密,连接到 SQL Azure 数据库失败