SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm retrieving different custom and default user properties from the my sites profile in a webpart.

The Problem is, if i'm trying to retrieve profile information which hasn't been set yet the webpart throws a System.NullReferenceException.

How can i check if the property is set to work around that problem?

share|improve this question
please post some code, or we cant help you. – Anders Rask Aug 23 '11 at 14:08
Here is the code where the exception is thrown: result = u[property].Value.ToString(); – Peter Aug 30 '11 at 8:52
up vote 1 down vote accepted

if (properties["MyProperty"] != null) { ... ?

share|improve this answer
Sorry, doesn't work. Debugger jumps not in the if-clause.. don't know why :/ Looks like this:if (u[property] == null) { result = String.Empty; } else { result = u[property].Value.ToString(); } – Peter Sep 13 '11 at 10:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.