Objective reference not set to instance of an object - error is coming when calling profile subsystem i.e CommerceContext.Current.ProfileSystem
-
Friday, March 26, 2010 11:28 AM
Hi All,
I am creating a Profile Independently from a Commerce Server Site using ASP.NET web application. When i am trying to execute below code I am getting "Object reference not set to an instance of an object" error at the below code area.
ProfileContext ctxt = CommerceContext.Current.ProfileSystem;
Should I add any configuration settings code in Web.Config of ASP.NET webapplication? Please help me.
Please find my code snippet .
// Declare and set variables.
String newGuid = "{" + Guid.NewGuid().ToString() + "}";
String password = "password";
String eMail = "someone@example.com";
String passwordQuestion = "My Question";
String passwordAnswer = "My Answer";
String accountStatus = "1"; //activetry
{
// Get the Profiles runtime object.
ProfileContext ctxt = CommerceContext.Current.ProfileSystem;// Create a new profile object.
Profile prof = ctxt.CreateProfile(newGuid, "UserObject");// Set the profile properties.
prof.Properties["GeneralInfo.user_security_password"].Value = password;
prof.Properties["GeneralInfo.email_address"].Value = eMail;
prof.Properties["GeneralInfo.password_question"].Value = passwordQuestion;
prof.Properties["GeneralInfo.password_answer"].Value = passwordAnswer;
prof.Properties["AccountInfo.account_status"].Value = accountStatus;// Update the profile with the property values.
prof.Update();// Write a message to the console when the profile is successfully created.
Console.WriteLine("Successfully created profile");Thanks in advance !!
All Replies
-
Friday, March 26, 2010 12:34 PM
Yes, you have to set a couple of configuration in your web.config file. If you give us a copy of it we can help you on the missed one.
http://www.gaelduhamel.fr;http://www.gaelduhamel.com;http://www.twitter.com/GaelDuhamel; -
Friday, March 26, 2010 12:36 PM
either siteAgent or serviceAgent can be used
have a look at
http://blogs.msdn.com/akfaulkner/default.aspx?p=2
http://commserver07.blogspot.com/2007/01/pulling-out-catalog-context.html

