0

"serialization exception thrown in System.Web.Profile.DefaultProfile"

I'm using a lot of custom classes but have marked them all with serializable attribute. The website loads properly initially on the default page, but once a redirection happens to a different page, which inherits the custom "BasePage" class, instead of the default Page class, this exception is thrown :

Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.

one of the statements in the intellitrace says something like, "failed to serialize System.Web.Profile.DefaultProfile could not be serialized". Isn't it an inbuilt .NET object, and if so cannot I presume that it should be serializable in all cases???

3 Answers 3

1

I just ran into this same problem yesterday. The custom object isn't necessarily the problem, but objects inside of that. If you have things like System.Drawing.Image or Dictionary<> or anything else that isn't inherently serializable, its gonna blow up. So you're gonna have to do some digging. I had to do things like convert a List into a string[] to pass it to the web service (which receives a List but shows in intellisense as receiving a string[]).

So I'd rethink that. We also found out that once we got that working in the test server, we weren't done. As soon as we published the web service, other problems started popping up that were similar. Images were not serializable so we converted them to byte[] before sending them, Dictionaries were also not serializable.

I realize this isn't much of an answer, but hopefully of some help.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it's definitely of some help, especially the image thing(I wouldn't have thought about that at first).
0

It is built into ASP.Net, but that doesn't mean it's serializable. There's lots of framework classes that are not serializable.

But also, the Default profile is made to work with the asp.net profile mechanism. Why are you attempting to store that in session? It already has it's own configurable storage mechanism. I think this may be a case where you're in a place where you're fighting the system.

5 Comments

I'm not even trying to store it into the session. This problem appears when the application tries to redirect to a page that inherits "BasePage"(let's say) instead of the default "Page" class. And of course, BasePage:Page and also is marked as serializable.
So what is in this "BasePage" class? It must be adding something to the session. Is there anything in there that accesses the Session object?
I don't see any. Could you please tell me(or atleast a workaround), how would I save a userprofile in a session object if I'm using stateserver session mode. Maybe that would provide some hint.
You can't if the object you are trying to save is not serializable. You would have to copy it's data to a different object that is serializable. It must be serializable to store it in session state if session state is SQL or State Server. I would look for anything in your project where "Session" is accessed and see if you can find where that object is getting placed there.
Thanks swannee, maybe that's the approach I'd take(at least for now).
0

For my particular case, I worked around the problem by creating a new custom class with a Serializable attribute, with a property that would return the HttpContext.Current.Profile object. And then whenever I needed to add the profile into session, I'm adding it through the property of this newly created class. Thanks to @swannee and @Sinaesthetic for their ideas.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.