Skip to content

Unexpected behavior for Get<T> on complex objects #6

@gortok

Description

@gortok

I'm using the "Get this object if it exists, if not Create it" pattern, and one issue I'm seeing is when I get Store.Get<T> for a complex object, it'll return an object (with default values) even if that object doesn't exist in redis. Which I didn't expect because I thought it would use the redis GET command.

Here's the code:

public interface IA 
{
  string Id {get;}
  IB B {get; set;}
}

public interface IB
{
  IList<IC> C {get; set;}
}

And you can imagine what IC looks like. Anyway, when I try to get an object from Redis, I get an ArgumentNullException from Jil because IA.B is null; which I wouldn't have expected.

        var user = Store.Get<IA>("myIdNotInRedis");
        if (user.B == null) //throws exception here

System.ArgumentNullException was unhandled
HResult=-2147467261
Message=Value cannot be null.
Parameter name: text
Source=Jil
ParamName=text
StackTrace:
at Jil.JSON.Deserialize[T](String text, Options options) in C:\Users\kmontrose\Dropbox\jil\Jil\JSON.cs:line 4751
at Rol.FromRedisValue`1.<>c.b__1_3(RedisValue v, Store s)
at Rol.RedisOperations.GetHashValue[TKey,TValue](Store store, RedisKey hashName, TKey field)
at StackStats.Persistence.User.GetUser(String userId, String siteName) in c:\projects\shift\src\StatPersistence\Persistence\StackUser.cs:line 45
at XmlProcessor.BadgesProcessor.Process(XElement element, String siteName) in c:\projects\shift\src\XmlProcessor\BadgesProcessor.cs:line 34
at XmlProcessor.DocumentProcessor.processFile(IProcessor processor, XmlReader reader, String siteName) in c:\projects\shift\src\XmlProcessor\DocumentProcessor.cs:line 76
at XmlProcessor.DocumentProcessor.ProcessXmlDocument(String xmlFile) in c:\projects\shift\src\XmlProcessor\DocumentProcessor.cs:line 45
at StatRunner.Program.Main(String[] args) in c:\projects\shift\src\StatRunner\Program.cs:line 28
InnerException:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions