locked
Azure Redis Cache Error "Value of type cannot be converted" RRS feed

  • Question

  • User-2089506584 posted

    Hello,

    Why I get this error using Azure Redis Cache (Preview) "Value of type 'System.Collections.Generic.List(Of Person)' cannot be converted to 'StackExchange.Redis.RedisValue'."

    [Serializable()]
    public class Person
    {
    private string FirstName;
    private string LastName;
    }
    using StackExchange.Redis;
    ConnectionMultiplexer Connection = ConnectionMultiplexer.Connect("website.redis.cache.windows.net,ssl=true,password=...");
    
    IDatabase cache = Connection.GetDatabase();
    List<Person> p = new List<Person>();
    
    p.Add(new Person {
    FirstName = "Mike",
    LastName = "Shourge"
    });
    p.Add(new Person {
    FirstName = "Jenny",
    LastName = "Baldwin"
    });
    
    cache.StringSet("cacheKey", p.ToList, TimeSpan.FromMinutes(10), When.Always, CommandFlags.None); //<<--Error Here


    -imperialx

    Thursday, September 11, 2014 11:38 PM

Answers

  • User-417640953 posted

    Hi imperialx,

    Thank you post the issue to our forum.

    Azure Redis Cache (Preview) can work with .NET objects as well as primitive data types, but before a .NET object can be cached it must be serialized.

    This is the responsibility of the application developer. This gives the developer flexibility in the choice of the serializer.

    Get more information please follow below article.

    http://msdn.microsoft.com/en-us/library/dn690521.aspx#Objects

    Thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 14, 2014 10:39 PM

All replies

  • User-417640953 posted

    Hi imperialx,

    Thank you post the issue to our forum.

    Azure Redis Cache (Preview) can work with .NET objects as well as primitive data types, but before a .NET object can be cached it must be serialized.

    This is the responsibility of the application developer. This gives the developer flexibility in the choice of the serializer.

    Get more information please follow below article.

    http://msdn.microsoft.com/en-us/library/dn690521.aspx#Objects

    Thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 14, 2014 10:39 PM
  • User-2089506584 posted

    Thanks!

    IDatabase cache = Connection.GetDatabase();

    ...

    SampleStackExchangeRedisExtensions.Set(cache, "cacheKey", p.Tolist)

    List
    <Person> getPersonLists = SampleStackExchangeRedisExtensions.Get(cache, "cacheKey")

    foreach item in getPersonLists {
    ...
    }


    Sunday, September 14, 2014 11:18 PM