WELCOME

This blog is where I post about my consulting work with Microsoft Technologies, and other random tidbits that don't fit in my Photo Blog or my Iraq Blog.

Friday, December 4, 2009

SetPropertyValues never called in custom ProfileProvider

I've been writing a custom ASP.NET MembershipProvider, RoleProvider, and ProfileProvider from scratch with Amazon SimpleDB as a backend. Everything went swimmingly with Membership and Roles, but I've spent an embarassing amount of time fighting with Profile...

Profile's underlying object model is complex and less than intuitive. The challenge for me was trying to figure out what things had to be implemented in order to get basic functionality working.

The major roadblock I ran into was that at the point that I was code complete and everything seemed like it "should" have been working I couldn't get anything to save. No errors, but nothing was saving.

All Profile saves go through SetPropertyValues and when I set a break point on my overridden version of this method it was just never getting hit.

After hours of trashing about I finally found the answer in this thread: http://forums.asp.net/t/635411.aspx

The gist of the problem is that before every save Profile calls GetProfileValues, and if the result returned by GetProfileValues isn't properly populated SetPropertyValues just doesn't get called. Highly unintuitive.

Here is the quote from the thread that finally solved the problems for me:

"Basically, somewhere in GetPropertyValues, there should be code new'ing up SettingsPropertyValue instances that looks like:

SettingsPropertyValue sv = new SettingsPropertyValues(SettingsPropertyInstanceGoesHere);

You get the SettingsProperty instance from the SettingsPropertyCollection that is passed in as a parameter to the GetPropertyValues method."

When I'm done these providers will be published on Codeplex as part of my ScrappyDB C# library for SimpleDB.