ProfileCommon in WAP working at run-time but not at compile-time

852 views Asked by At

I have a Web Application Project and implemented profile properties in the web.config. When I found that I couldn't access the ProfileCommon object I googled and found some workarounds:

And so on. But nobody said that I have a ProfileCommon object at run-time. Here's my example:

<profile enabled="true">
  <properties>
    <add name="AdminRemark"/>
    <add name="FacilityID" type="System.Int64" defaultValue="1"/>
  </properties>
</profile>

This line compiles well and works, but I have the hard-coded property name:

rcbFacilityID.SelectedValue = 
    (ProfileBase.Create(userCurrent.UserName) as ProfileBase)
    .GetPropertyValue("FacilityID").ToString();

But this line doesn't compile and gives the error: The type or namespace name 'ProfileCommon' could not be found (are you missing a using directive or an assembly reference?)):

rcbFacilityID.SelectedValue = 
    (ProfileBase.Create(userCurrent.UserName) as ProfileCommon)
    .FacilityID.ToString();

But at run-time I tried to execute the line in the Visual Studio Watch window and it worked! It event displayed the type of ProfileBase.Create(userCurrent.UserName) as ProfileCommon without the cast. Intellisense didn't work, but a could inspect the object and I saw that it had both profile properties defined.

I don't mind working with hard-coded profile property names if it's the only way except the custom ProfileCommon class, but I'd like an explanation why the ProfileCommon class is available at run-time and not a compile-time?

1

There are 1 answers

3
loodakrawa On BEST ANSWER

ProfileCommon is not available at compile time because it is a class created when the application is started. This is due to the properties you can define inside the profile element in web.config so they can be dynamically added. See the remarks in the official documentation.