I am writing a feature, on activation it must create an entry in a list for every entry in a document library. I am using a webservice to get to the list which is on another sharepoint site. I am using the configurationmanager to get my credentials for the service. What goes wrong is, when I debug I get an object reference not set error. When I comment out my

    subscriberListService.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["Username"].ToString(), ConfigurationManager.AppSettings["Password"].ToString(), ConfigurationManager.AppSettings["Domain"].ToString());

line and activate, it works fine. If I put a breakpoint in my code just before the commented out line listed above and use the immediate window to execute the above line of code, it works fine, it finds the entries in the appsettings section in the config file and correctly applies them to the subscriberListService credentials.

Why is it having configuration manager issues on feature activation?

1 Answer 1


I suspect you have saved your app settings in the wrong web.config. You need to be cognicant of the app domain being used here. In other words, if the call is originated from a web service, then the web service App domain (and subsequent web.config) is used. Make sure you add the AppSettings for Username, Password,Domain in the correct web.config.

Also, If you are using Sharepoint 2010, you shouldn't be saving Passwords andd username in web configs as it's not secure. Rather make use of the Secure Store service. Read more here: http://blog.mikehacker.net/2010/01/20/sharepoint-2010-retrieving-credentials-from-secure-store-service/

  • If i was saving the settings in the wrong .config file then it would also throw an object reference error when executing the code in the immediate window, I'll investigate the secure store service, thanks! Feb 4, 2013 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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