Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couchbase.Extensions.Session - GetObject extension throws exception if object not in session #59

Open
mgroves opened this issue Nov 15, 2018 · 0 comments

Comments

@mgroves
Copy link

mgroves commented Nov 15, 2018

For example, if there is no "user" object in the session store yet, then this:

HttpContext.Session.GetObject<dynamic>("user");

Will throw a NullReferenceException. A workaround would be:

if(HttpContext.Session.Get("user") != null)
    model.User = HttpContext.Session.GetObject<dynamic>("user");

But that's probably too much extra code, and worse case maybe it results in 2 get operations, when only 1 is necessary?

Maybe a TryGetObject extension is in order? Or some sort of overload of GetObject to supply a default value? Or both?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant