-
Notifications
You must be signed in to change notification settings - Fork 128
Description
Hi, I'm trying to setup and environment where a console app, based on .NET461, adds elements to a cache, elements that are getted by a .NETCore 3.1 web app. The console app uses the ICache interface, while the .NETCore web app uses the IDIstributedCache interface. All packages are updated to the latest available. When the .NETCore web app executes the GetString() method, an exception arises from the NCache subsystem and no element returns.
The relevant piece of code of the console app is:
string cacheKey = $"elm:pagestree|idcn:{idCN}";
string cacheItem = Newtonsoft.Json.JsonConvert.SerializeObject(shadowPagesTreeList, Newtonsoft.Json.Formatting.None);
if (cacheManager.Contains(cacheKey))
{
cacheManager.Remove(cacheKey);
}
cacheManager.Insert(cacheKey, cacheItem);
The relevant piece of code of the web app is:
string cacheKey = $"elm:pagestree|idcn:{idCN}";
var cacheItem = _distributedCache.GetString(cacheKey);
if (cacheItem != null)
{
l = System.Text.Json.JsonSerializer.Deserialize<List<Models.PagesTreeElement>>(cacheItem);
}
The exception arises when executing the GetString() or Get() methods and is:
_System.Configuration.Provider.ProviderException
HResult=0x80131500
Message=Unable to cast object of type 'System.String' to type 'System.Byte[]'.
Source=Alachisoft.NCache.DistributedCache
StackTrace:
at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.RaiseException(Exception exc)
at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.LogError(Exception exception)
at Alachisoft.NCache.Caching.Distributed.NCacheDistributedCache.Get(String key)
at Microsoft.Extensions.Caching.Distributed.DistributedCacheExtensions.GetString(IDistributedCache cache, String key)
at IsibetPRO.IsiPlanner.ServiceWebApp.Controllers.MainController.GetPagesTree(Byte appType) in D:\Users\andre\Source\Repos\IsiPlanner\IsibetPRO.IsiPlanner.ServiceWebApp\Controllers\MainController.cs:line 262
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Byte[]'._
The cache, server side, is configured as in file attached.
Please note that other combinations of data-format and serialization parameters don't resolve.
If the web app itself adds and gets elements from the cache, all works as expected.
Thanks in advance, Andrea Valori.