0

I'm trying to implement Redis caching in our sitecore setup, but I'm having trouble doing so. We are running dotnet framwork 4.8 in a containerized setup. I've install StackExchange.Redis Nuget package version 2.7.27, and I'm trying to write to the cahce using db.StringSet(applicationCacheKeyEnum.ToString(), objectJsonString, TimeSpan.MaxValue, true, When.Always);. My code compiles, but at runtime I get the following error:

{
"Message": "An error has occurred.",
"ExceptionMessage": "Method not found: 'Boolean StackExchange.Redis.IDatabase.StringSet(StackExchange.Redis.RedisKey, StackExchange.Redis.RedisValue, System.Nullable`1<System.TimeSpan>, Boolean, StackExchange.Redis.When, StackExchange.Redis.CommandFlags)'.",
"ExceptionType": "System.MissingMethodException",
"StackTrace": "......"}

As far as I can see the signature of my method call matches Redis' StringSet() method, so I don't understand why this is happening. Below is the method in which I'm trying to set the cache value:

    public void AddToCache(ApplicationCacheKeyEnum applicationCacheKeyEnum, object theObject)
{
    IDatabase db = _redisAccessor.Redis.GetDatabase(0);
    string objectJsonString = JsonConvert.SerializeObject(theObject, Formatting.Indented);
    db.StringSet(applicationCacheKeyEnum.ToString(), objectJsonString, TimeSpan.MaxValue, true, When.Always);
}

Contents of Packages.Props:

<?xml version="1.0" encoding="utf-8"?>
<Project 
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
    <PlatformVersion>10.3.0</PlatformVersion>
</PropertyGroup>
<ItemGroup>
    <PackageReference Update="Microsoft.AspNet.Mvc" 
Version="5.2.4" />
    <PackageReference Update="Microsoft.AspNet.Web.Optimization" 
Version="1.1.3" />
    <PackageReference Update="Microsoft.AspNet.WebApi.Client" 
Version="5.2.6" />
    <PackageReference Update="Microsoft.AspNet.Razor" 
Version="3.2.7" />
    <PackageReference Update="Microsoft.AspNet.WebPages" 
Version="3.2.7" />
    <PackageReference Update="Microsoft.AspNet.WebApi" 
Version="5.2.9" />
    <PackageReference Update="Microsoft.AspNet.WebApi.Core" 
Version="5.2.9" />
    <PackageReference Update="Microsoft.AspNet.WebApi.WebHost" 
Version="5.2.9" />
    <PackageReference Update="Microsoft.AspNet.WebApi.Cors" 
Version="5.2.6" />
    <PackageReference 
Update="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" V 
ersion="3.6.0" />
    <PackageReference 
Update="Microsoft.CrmSdk.XrmTooling.CoreAssembly" 
Version="9.1.0.110" />
    <PackageReference 
Update="Microsoft.Extensions.Caching.StackExchangeRedis" 
Version="6.0.0.0" />
    <PackageReference 
Update="Microsoft.Extensions.Configuration.Abstractions" 
Version="6.0.0.0" />
    <PackageReference 
Update="Microsoft.Extensions.DependencyInjection" 
Version="6.0.0.0" />
    <PackageReference 
Update="Microsoft.Extensions.DependencyInjection.Abstractions" 
Version="6.0.0.0" />
    <PackageReference 
Update="Microsoft.Extensions.Logging.Abstractions" 
Version="6.0.1" />
    <PackageReference Update="Microsoft.Extensions.Http" 
Version="2.1.1" />
    <PackageReference 
Update="Microsoft.IdentityModel.Clients.ActiveDirectory" 
Version="4.5.0" />
    <PackageReference 
Update="Microsoft.IdentityModel.JsonWebTokens" Version="5.4.0" 
/>
    <PackageReference 
Update="Microsoft.IdentityModel.Protocols.OpenIdConnect" 
Version="5.3.0" />
    <PackageReference Update="Microsoft.IdentityModel.Protocols" 
Version="5.3.0" />
    <PackageReference Update="Microsoft.IdentityModel.Tokens" 
Version="5.4.0" />
    <PackageReference Update="Microsoft.Xrm.Client.2015" 
Version="7.0.1" />
    <PackageReference Update="Microsoft.Web.Infrastructure" 
Version="1.0.0" />

    <PackageReference Update="jose-jwt" Version="2.5.0" />
    <PackageReference Update="ExpressiveAnnotations" 
Version="2.9.6" />
    <PackageReference Update="RestSharp" Version="106.15.0" />
    <PackageReference Update="RestSharp" Version="105.1.0" />
    <PackageReference Update="Newtonsoft.Json" Version="13.0.1" 
/>
    <PackageReference Update="jose-jwt" Version="2.5.0"/>
    <PackageReference Update="ExpressiveAnnotations" 
Version="2.9.6"/>
    <PackageReference Update="FluentResults" Version="3.0.0" />
    
    <PackageReference Update="System.Text.Encodings.Web" 
Version="6.0.0.0" />
    <PackageReference Update="System.Memory" Version="4.5.2" />
    <PackageReference Update="System.IdentityModel.Tokens.Jwt" 
Version="5.4.0" />
    <PackageReference 
Update="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" 
/>

    <PackageReference Update="Sitecore.Kernel" 
Version="$(PlatformVersion)" />
    <PackageReference Update="Sitecore.Mvc" 
Version="$(PlatformVersion)" />
    <PackageReference Update="Sitecore.ExperienceEditor" 
Version="$(PlatformVersion)" />
    <PackageReference Update="Sitecore.ExperienceEditor.Speak" 
Version="$(PlatformVersion)" />
    <PackageReference Update="Sitecore.Assemblies.Platform" 
Version="$(PlatformVersion)" />
    <PackageReference Update="Sitecore.ContentSearch" 
Version="$(PlatformVersion)" />
    <PackageReference Update="Sitecore.ContentSearch.Linq" 
Version="$(PlatformVersion)" />
    <PackageReference Update="Sitecore.ExperienceForms" 
Version="$(PlatformVersion)" />
    <PackageReference Update="Sitecore.ExperienceForms.Mvc" 
Version="$(PlatformVersion)" />
    <PackageReference Update="Sitecore.Logging" 
Version="$(PlatformVersion)" />
    <PackageReference Update="Sitecore.Services.Infrastructure" 
Version="$(PlatformVersion)" />
    <PackageReference Update="Sitecore.LayoutService" 
Version="9.0.310" />
    <PackageReference 
Update="Sitecore.Assemblies.SitecoreHeadlessServicesServer" 
Version="21.0.583" />
    <PackageReference Update="Sitecore.Framework.Conditions" 
Version="6.0.0" />
    <PackageReference 
Update="Sitecore.Framework.Rules.Abstractions" Version="6.0.0" 
/>

    <PackageReference Update="Helpfulcore.Caching" 
Version="1.0.1" />
    <PackageReference Update="Helpfulcore.Caching.Sitecore" 
Version="1.0.4" />
    <PackageReference Update="Helpfulcore.Caching.Sitecore.Core" 
Version="1.0.2" />

    <PackageReference Update="xWrap.Framework" Version="1.0.21" 
/>
    <PackageReference Update="xWrap.Mvc.Framework" 
Version="1.0.21" />

    <PackageReference Update="Configy" Version="1.0.0.0" />
    <PackageReference Update="Kamsar.WebConsole" 
Version="2.0.1.0" />
    <PackageReference Update="MicroCHAP" Version="1.2.2.2" />
    <PackageReference Update="Rainbow" Version="2.1.4.0" />
    <PackageReference Update="Rainbow.Storage.Sc" 
Version="2.1.4.0" />
    <PackageReference Update="Rainbow.Storage.Yaml" 
Version="2.1.4.0" />
    <PackageReference Update="Unicorn" Version="4.1.6.0" />
    <PackageReference Update="Unicorn.Roles" Version="4.1.6.0" 
/>
    <PackageReference Update="Unicorn.Users" Version="4.1.6.0" 
/>

    <PackageReference Update="MSTest.TestAdapter" 
Version="3.1.1"/>
    <PackageReference Update="MSTest.TestFramework" 
Version="3.1.1"/>
    <PackageReference Update="Moq" Version="4.20.69"/>
    <PackageReference Update="StackExchange.Redis" 
Version="2.7.27" />
</ItemGroup>
</Project>

In csproj file i have the following ItemGroup:

<ItemGroup>
    <PackageReference Include="Sitecore.Assemblies.Platform">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNet.Mvc" />
    <PackageReference Include="Sitecore.Kernel" />
    <PackageReference Include="Sitecore.Mvc" />
    <PackageReference Include="StackExchange.Redis" />
  </ItemGroup>

Can anyone help me understand, what causes the error?

8
  • 4
    "I've install StackExchange.Redis Nuget package version x.x.x.x" - I'd be surprised if "x.x.x.x" is actually the version you're using, and seeing as this is very likely to be a versioning problem, the actual version is really important. Commented Mar 11, 2024 at 10:10
  • 1
    Additionally, if you could provide a minimal reproducible example so that others could reproduce the problem, that would make a huge difference. Commented Mar 11, 2024 at 10:10
  • @JonSkeet You're right, of course, about the version number. I menat to get the exact version number before posting, but forgot, sorry - i've edited the question Commented Mar 11, 2024 at 11:52
  • Okay, that's a start. Now for more information - are you able to run the code when it's not containerized? What projects are involved? Basically the more information you can provide - again, ideally a minimal reproducible example - the more likely it is that we can help you. Commented Mar 11, 2024 at 11:57
  • As @JonSkeet said - try providing a minimal reproducible example or at least share contents of relevant .csproj files. Commented Mar 11, 2024 at 12:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.