我正在尝试向我的 .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 包:
- Microsoft.Extensions.Caching.Redis 版本 2.0.1
- 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/