Skip to content

Retrieving a hash that was set without a property present throws exeption on SendToJson #120

Closed
@diogonborges

Description

@diogonborges

Got this error when using Redis Enterprise on Azure

and running the following line:

The model is

[Document(IndexName = "asset_idx", Prefixes = new[] { nameof(Model) }, StorageType = StorageType.Hash)]
public class Model
{
    [Searchable(Sortable = true, Aggregatable = true, PropertyName = "Id")]
    public string Id { get; set; }
    
    ....
    
    
    [Searchable(Sortable = true, Aggregatable = true, PropertyName = "D_State")]
    public string D_State { get; set; }
}

The line of code that throws exception

var entry = _cacheCollection.FirstOrDefault(x => x.Id == "ARandomValidId");
System.Collections.Generic.KeyNotFoundException: The given key 'D_State' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Redis.OM.RedisObjectHandler.SendToJson(IDictionary`2 hash, Type t)
   at Redis.OM.RedisObjectHandler.FromHashSet[T](IDictionary`2 hash)
   at Redis.OM.Searching.SearchResponse`1..ctor(RedisReply val)
   at Redis.OM.Searching.RedisQueryProvider.ExecuteQuery[T](Expression expression)
   at Redis.OM.Searching.RedisQueryProvider.FirstOrDefault[TResult](Expression expression)
   at Redis.OM.Searching.RedisQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)

This happens because I've stored a hash entry that does not contain that string property and then when retrieving, the Json conversion looks to be failing.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions