The following piece of sharepoint code is attempting to list all the user profile properties as well as their values
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite(args[0], SPUserToken.SystemAccount))
{
var profileManager = new UserProfileManager(SPServiceContext.GetContext(site));
UserProfile userProfile = profileManager.GetUserProfile(args[1]);
foreach (var Property in userProfile.Properties)
{
Console.WriteLine("Property DisplayName = " + Property.DisplayName + "; " + "Property Name = " + Property.Name);
if (userProfile[Property.Name] != null)
{
Console.WriteLine("user profile property value " + Property.Name + " is not null");
Console.WriteLine("property Value = " + userProfile[Property.Name].ToString());
}
else
{
Console.WriteLine("property Value = null");
}
}
}
}
}
this produces the following output :
This shows the exception is coming on the line where it is trying to check if the user profile property value is null
if (userProfile[Property.Name] != null)
But i am already comparing it to null. So why should it give the error that the object is null?
Can someone please give some clarification?
the userProfile is not null , the Property.Name is also not null and i am checking if the userProfile[Property.Name] != null. But it blows up with the error. What on earth is going on?