Setting SharePointOnlineCredentials - catastrophic failure - COMException

2.4k views Asked by At

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.

6

There are 6 answers

0
Madison On

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.

1
Melvin Vermeer On

Today I came across the same issue, it occurred on an azure web role. What I did after deploying the web role to azures:

  1. Connect to web role server via rdp.
  2. Install SharePoint Client Components SDK
  3. Go IIS Manager
  4. Change Application Pool Identity to local Administrator (the account I created to log on the web role server)
0
Catherine On

I had this error message and it turned out that ScanSafe was blocking bin files, so we couldn't access http://clientconfig.microsoftonline-p.net/ppcrlconfig600.bin, which is needed to login.

Once we updated the settings to allow the download of binary files it resolved the error.

0
user1805377 On

It got resolved after I set Internet Security Settings. Go to Internet Options-> Security -> Internet -> Custom Level -> Enable .Net Framework and other few activex controls.

0
Iveusse On

I had the same exception. To resolve it :

Connect to http://login.microsoftonline.com in IE with the account that you will use in your app (or app pool) and install the certificate from the page.

It solved my problem.

Hope can help.

0
BoKDamgaard On

I had the same problem, and tried all of the above things, without luck. It turned out to be my antivirus Bitdefender 2013. When I disabled the scanner it worked.