I have the following code in use within 2 web application projects, both of which are part of the same solution. The two projects interact with each other, one contains a web service and code that builds a Pivot Viewer collection (CXML + images), the other is a simple web application that hosts the container page that displays the Pivot Viewer control.
The two projects need to interact with a SharePoint site that contains a couple of lists. The lists contain data used to build the CXML collection and to log access to data items exposed by the collection. The following code exists in both projects.
using SP = Microsoft.SharePoint.Client;
///.......
string siteURL = ConfigurationManager.AppSettings["SharePointURL"];
ClientContext clientContext = new ClientContext(siteURL);
string listName = ConfigurationManager.AppSettings["ListName"];
SP.List downloadRequestList = clientContext.Web.Lists.GetByTitle(listName);
string username = ConfigurationManager.AppSettings.Get("SharePointCredentialUsername");
string userkey = ConfigurationManager.AppSettings.Get("SharePointCredentialPassword");
SecureString securekey = new SecureString();
for (int i = 0; i < userkey.Length; i++)
securekey.AppendChar(userkey[i]);
SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(username, securekey);//error occurs here
clientContext.Credentials = credentials;
The code executes without problems in one project (web service), the other project (web application) throws a COMException on the line where SharePointOnlineCredentials are instantiated (2nd from bottom in snippet above).
Exception details:
Message:{"Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"}
Source "Microsoft.SharePoint.Client.Runtime"
HResult/ErrorCode -2147418113
StackTrace at Microsoft.SharePoint.Client.Idcrl.ManagedIdcrl.EnsureInited() at Microsoft.SharePoint.Client.Idcrl.ManagedIdcrl.LogonIdentity(String username, SecureString password) at Microsoft.SharePoint.Client.SharePointOnlineCredentials..ctor(String username, SecureString password) at PivotServer.Download.SaveDownloadListItem() in download.aspx.cs:line 104
I have matched the web.config file for both projects, they contain the same entries. A related thread suggested setting the Application Pool Identity to "Local System", that did not make a difference.
Thanks in advance, any advice, suggestions, code samples dearly appreciated.
I had the same error and none of the previous answers resolved this. I ended up going to the site application in IIS Manager and setting the physical path credentials under Advanced Settings.