【问题标题】:SharePointOnlineCredentials throwing System.Runtime.Interopservices.COMException in console applicationSharePointOnlineCredentials 在控制台应用程序中抛出 System.Runtime.Interopservices.COMException
【发布时间】:2014-01-02 13:20:51
【问题描述】:

我是 sharepoint 的新手,我正在在线使用 sharepoint,我正在编写代码来简单地打印网站标题和创建日期。这是我的代码:

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);
            }
        }
    }
}

首先我没有 Microsoft.Sharepoint.client.dll 和 Microsoft.Sharepoint.client.runtime.dll 的 dll 文件,所以我从 microsoft 安装了 Sharepoint Client SDK,并在我的 C:\Program 中获得了 dll 文件Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI。

在运行代码时,我得到以下行的异常:

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

例外:

System.Runtime.Interopservices.COMException {“灾难性故障(HRESULT 异常:0x8000FFFF (E_UNEXPECTED))”}

堆栈跟踪:

   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)

为了澄清,我输入了正确的凭据并且代码没有任何问题,因为上面相同的代码在具有 Windows 8 32 位操作系统和 Visual Studio 2013 的不同系统上完美运行 .

在运行 Windows 7 和 8(均为 64 位)的其他 2 个系统上失败。 它与Windows有什么关系? 很抱歉发了这么长的帖子,但是在 stackoverflow 上有类似的问题,我找不到我的答案,所以我想缩小我的问题范围。

【问题讨论】:

  • 这行得通吗?:clientContext.Credentials = new NetworkCredential(myusername, password);
  • 不,我在使用 SharepointOnlineCredentials 之前尝试过此方法,但服务器在运行时抛出 403 禁止错误。

标签: c# windows visual-studio-2010 sharepoint dll


【解决方案1】:

同样的错误,在nuget控制台安装sharepoint.client 16版本解决 PM>Install-Package Microsoft.Sharepoint.2013.Client.16

谢谢大家!

【讨论】:

    【解决方案2】:

    请安装SharePoint Server 2013 Client Components SDK

    客户端组件还包含所需的 COM 库,请参阅相关的link

    【讨论】:

    • 我确实安装了sdk,我在我的问题中提到过。
    【解决方案3】:

    我遇到了类似的错误。我更新了 Microsoft SharePoint 客户端 DLL,现在它可以工作了。我不再需要安装 SDK。 从这里下载 DLL-https://www.nuget.org/packages/Microsoft.Sharepoint.2013.Client.16/

    【讨论】:

      猜你喜欢
      • 2015-12-11
      • 1970-01-01
      • 2014-08-01
      • 1970-01-01
      • 2014-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多