As the title says, and similar to this question in the way that I am setting an object using the SessionHelper.SetValue method, it is returning null when I try to access it. The codefile is located within the App_Code folder, again like the question above, but the solution to that question (using the traditional HttpContext.Current.Session property) does not work either and yields the same error.
The strangest part to this is that it was working, but suddenly stopped. It was even deployed to production. It only stopped working once I started working on a different part of the pipeline. We were previously using a Web Service to expose server-side methods, and are now wanting to change to an custom ApiController. I've made the changes on my local machine, where the error is occurring. I can't imagine that being the reason for this new error due to the explanation below. I'm also using the same Session logic in a web part on the same page but for a different purpose, and that is functioning.
My debugging process to confirm that it's the SessionHelper method that's failing is as follows:
ObjectName obj = new ObjectName { property1 = "string" }
EventLogProvider.LogInformation("Class", "Method", obj.property1);
SessionHelper.SetValue("key", obj);
var obj1 = (ObjectName)SessionHelper.GetValue("key");
EventLogProvider.LogInformation("Class", "Method", obj1.property1);
The data is present and correct within the first Event Log, but a null reference error is thrown when trying to access obj1. I even tried simplifying this process by simply throwing a random string into the SetValue method like so:
SessionHelper.SetValue("key", "random text");
string str = ValidationHelper.GetString(SessionHelper.GetValue("key"), string.Empty);
EventLogProvider.LogInformation("Class", "Method", str);
Doing this returned a blank string in the Event Log.
Any advice would be appreciated.