SharePointOnlineCredentials throwing System.Runtime.Interopservices.COMException in console application

0

I am new to sharepoint, I am using sharepoint online, and I am writing code to simply print the websites title and date created. here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using System.Security;

namespace SharepointAccessList
{
    class Program
    {
        static void Main(string[] args)
        {
            using (ClientContext clientContext = new ClientContext("https://{sitename}.sharepoint.com//"))
            {
                SecureString password = new SecureString();

                foreach (char c in "{mypassword}".ToCharArray()) password.AppendChar(c);

                clientContext.Credentials = new SharePointOnlineCredentials("{myusername}", password);

                Web oWebsite = clientContext.Web;
                clientContext.Load(oWebsite);
                clientContext.ExecuteQuery();

                Console.WriteLine("Title: {0} Created: {1}", oWebsite.Title, oWebsite.Created);
            }
        }
    }
}

First I did not have the dll files Microsoft.Sharepoint.client.dll and Microsoft.Sharepoint.client.runtime.dll so I installed the Sharepoint Client SDK from microsoft, and I got the dll files in my C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI.

on running the code I get the exception on following line:

clientContext.Credentials = new SharePointOnlineCredentials("{myusername}", password);

Exception:

System.Runtime.Interopservices.COMException {"Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"}

Stack Trace:

   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 SharepointAccessList.Program.Main(String[] args) in c:\Users\Fortune4\Documents\Visual Studio 2012\Projects\SharepointAccessList2\SharepointAccessList2\Program.cs:line 21
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

For clarification, I've entered correct credentials and there is nothing wrong with the code because the above same code is running perfectly on a different system which has Windows 8 32 bit OS and visual studio 2013.

It is failing on my other 2 systems which are running on Windows 7 and 8, both 64 bit. does it have anything to do with Windows? Sorry for the long post, but there were similar questions on stackoverflow on which i couldn't find my answer so i wanted to narrow down my problem.

c#
windows
visual-studio-2010
sharepoint
dll
asked on Stack Overflow Jan 2, 2014 by Nabeel Bape

3 Answers

3

has the same error, solved with the installation of sharepoint.client 16 version in nuget console PM>Install-Package Microsoft.Sharepoint.2013.Client.16

thanks guys!

answered on Stack Overflow Jun 28, 2016 by R Naamän Villa O
0

Please install SharePoint Server 2013 Client Components SDK.

Client components also contain required COM library, see related link.

answered on Stack Overflow Jan 7, 2014 by Roman • edited May 23, 2017 by Community
0

I was getting a similar error. I updated the Microsoft SharePoint client DLLs and now it works. I do not need to install the SDK any more. Downloaded the DLLs from here- https://www.nuget.org/packages/Microsoft.Sharepoint.2013.Client.16/

answered on Stack Overflow May 10, 2016 by ubaid

User contributions licensed under CC BY-SA 3.0