Problem accessing Profiles in Console application

Last post 03-26-2007 1:22 AM by XiaoYong Dai - MSFT. 1 replies.

Sort Posts:

  • Problem accessing Profiles in Console application

    03-22-2007, 7:22 AM
    • Loading...
    • kreid
    • Joined on 10-19-2006, 12:15 PM
    • Posts 85

    Hi,

    I am having a strange problem whereby I can access Membership and MembershipUser perfectly from my console application, but accessing Profiles is causing an Exception.

    Firstly, I have a reference to System.Web in my project. In my class, I am including System.Web.Wrofile and System.Web.Security.

    I wanted to use ProfileCommon, but intellisense does not see this (why not!!?); so I am using ProfileBase in the following way:

      

    ProfileBase userProfile = ProfileBase.Create(mem.UserName, true);

     

    When this line is reached, my try catch gives me:

    System.Configuration.ConfigurationErrorsException: Attempting to load this property's type resulted in the following error: Could not load type 'CentralHostLibrary.UserAlertPrefObject' from assembly System.Web...

    I don't understand this. Why is it trying to look for my class library (CentralHostLibrary) in System.Web????

    Here is my app.config file:

     

    <configuration>
      <appSettings>
        <add key="ConnectionString" value="Data Source=localhost;Initial Catalog=MembershipDB;Integrated Security=True;"/>
      </appSettings>
      <connectionStrings>
        <remove name="LocalSqlServer"/>
        <add name="LocalSqlServer" connectionString="Data Source=localhost;Initial Catalog=MembershipDB;Integrated Security=True;" providerName="System.Data.SqlClient"/>
      </connectionStrings>
    
      <system.web>
        <roleManager enabled="true">
        </roleManager>
        <membership defaultProvider="AspNetSqlProvider" userIsOnlineTimeWindow="20">
          <providers>
            <clear/>
            <add name="AspNetSqlProvider" type="System.Web.Security.SqlMembershipProvider,
                    System.Web,
                    Version=2.0.3600.0,
                    Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="true" minRequiredPasswordLength="8" minRequiredNonalphanumericCharacters="1" passwordFormat="Hashed" description="Stores and retrieves membership data from the local Sql Server database"/>
          </providers>
        </membership>
        <profile defaultProvider="SqlProfileProvider">
          <providers>
            <remove name="AspNetSqlProfileProvider"/>
            <add name="SqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" applicationName="/" connectionStringName="LocalSqlServer"/>
          </providers>
          <properties>
            <add name="FirstName" type="string"/>
            <add name="LastName" type="string"/>
            <add name="Company" type="string"/>
            <add name="AlertPrefs" type="CentralHostLibrary.UserAlertPrefObject" serializeAs="Binary"/>
            <add name="PrefsChanged" type="bool" defaultValue="false"/>
          </properties>
        </profile>
      </system.web>
    </configuration>
     
     
  • Re: Problem accessing Profiles in Console application

    03-26-2007, 1:22 AM
    Answer
    kreid:

    I wanted to use ProfileCommon, but intellisense does not see this (why not!!?); so I am using ProfileBase in the following way:

     

    I can use ProfileCommon and this work will on my VS 2005

     You should enable the profile in “web.config” like this:

        <profile enabled="true">

          <properties>

            <add name="UICulture" allowAnonymous="true" defaultValue="fr-FR" />

            <add name="Culture" allowAnonymous="true" defaultValue="fr-FR" />

          </properties>

        </profile>

    When that is done, Create the profile and save the settings. Example:

            ProfileCommon pfc = (ProfileCommon)ProfileCommon.Create(Login1.UserName, true);

            pfc.UICulture = "John";

            pfc.Culture = "";

            pfc.Save();

     

    Hope it helps

    Best Regards
Page 1 of 1 (2 items)
Microsoft Communities
Page view counter