Task: I try to build shopping cart using session in .NET Core.
Error 1:
No overload for method 'Serialize' takes 1 arguments
Error 2:
Can't convert from string to 'Newtonsoft.Json.JsonReader'
In code => Deserialize<T>(value)
public static class SessionExtensions
{
public static void Set<T>(this ISession session, string key, T value)
{
session.setString(key, JsonSerializer.Serialize(value));
}
public static T Get<T>(this ISession session, string key)
{
var value = session.GetString(key);
return value == null ? default : JsonSerializer.Deserialize<T>(value);
}
}
I try to pass one argument to Serialize()
method, but I failed.
Because this method takes at least two arguments are textWriter and object.