Microsoft Developer Network > Forums Home > Commerce Server Forums > Commerce Server 2009 > Objective reference not set to instance of an object - error is coming when calling profile subsystem i.e CommerceContext.Current.ProfileSystem

Unanswered 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"; //active

            try
            {
                // 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