Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm in the beginning of creating a custom web part that allows users to add themselves to Audiences and I'm first trying to get a feel for the API, by trying to simply list all Audiences I have on my site:

class Program
{
    static void Main(string[] args)
    {
        try
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (var site = new SPSite("http://localhost/"))
                {
                    var context = SPServiceContext.GetContext(site);
                    var audManager = new AudienceManager(context);

                    AudienceCollection audCollection = audManager.Audiences;

                    foreach (Audience audience in audCollection)
                    {
                        Console.WriteLine(audience.AudienceName);
                    }
                }                                    
            });
        }
        catch(AudienceExecutionException ex)
        {
            Console.WriteLine(ex.ToString() + "\n\n");
            Console.Read();
        }
        catch (Exception exception)
        {
            Console.WriteLine(exception.ToString());
            Console.Read();
        }
    }
}

I can connect to the site but keep receiving the following error:

AudienceExecutionException was unhandled by user code
Retrieving overall status encountered an error. 
Error is: Object reference not set to an instance of an object.
share|improve this question

1 Answer 1

It seems that since Audiences are tied into the UserProfile service, you need to add yourself as Full Control to either the Administrators or Permissions tab for the User Profile Service Application. I added myself to both -- not sure which one did the trick though I'm inclined to say it's the Permissions tab that did the trick.

share|improve this answer

Your Answer

 
discard

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.