【问题标题】:Why does .NET Core 2.2 API with SharePointOnline CSOM throw "The process has no package identity"?为什么带有 SharePointOnline CSOM 的 .NET Core 2.2 API 会抛出“进程没有包标识”?
【发布时间】:2019-07-20 12:40:14
【问题描述】:

我有一个在 Windows Server 2012 R2 数据中心机器上的 IIS 上运行的 .NET Core 2.2 API。它使用来自 Nuget 包 Microsoft.SharePointOnline.CSOM 的 DLL。但是在调用方法ClientContext.ExecuteQueryAsync()时会抛出异常One or more errors occurred. (The process has no package identity. (Exception from HRESULT: 0x80073D54))

我已遵循以下指南:https://rajujoseph.com/getting-net-core-and-sharepoint-csom-play-nice/。我尝试了两种解决方案。第一个是创建一个 .NET Core 控制台解决方案,该解决方案调用包含 SharePoint CSOM 代码的 DLL。然后我尝试从 Windows Server 2012 R2 Datacenter 机器上的 IIS 上运行的 .NET Core 2.2 API 调用 DLL。但是这两种解决方案都会抛出与上面提到的相同的异常One or more errors occurred. (The process has no package identity. (Exception from HRESULT: 0x80073D54))

SharePointHelper.dll 代码:

using Microsoft.SharePoint.Client;
using System;
using System.Collections.Generic;
using System.Text;

namespace SharePointHelper
{
  public class SharePointHelper
  {

    public SharePointHelper() { }

    public void WriteFilesAndFolders(string siteUrl, string listName, string username, string password)
    {
      using (var context = new ClientContext(siteUrl))
      {
        context.Credentials = new SharePointOnlineCredentials(username, password);

        var folder = context.Web.GetFolderByServerRelativeUrl(listName);
        var subFolders = folder.Folders;
        var files = folder.Files;

        context.Load(folder);
        context.Load(subFolders);
        context.Load(files);

        if (context.HasPendingRequest)
          context.ExecuteQueryAsync().Wait();

        var subFolderEnumorator = subFolders.GetEnumerator();
        var filesEnumerator = files.GetEnumerator();
        PrintValues(subFolderEnumorator);
        PrintValues(filesEnumerator);
      }
    }

    private void PrintValues(IEnumerator<Folder> enumerator)
    {
      while (enumerator.MoveNext())
        Console.WriteLine(enumerator.Current.Name);
    }

    private void PrintValues(IEnumerator<File> enumerator)
    {
      while (enumerator.MoveNext())
        Console.WriteLine(enumerator.Current.Name);
    }

  }

}

.NET Core 2.2 服务代码调用 SharePointHelper.dll 中的方法:

public void SharePointTest()
    {
      string siteUrl = @"https://somecompany.sharepoint.com/sites/Test";
      string listName = "Documents";
      string username = "myemail@somecompany.com";
      string password = "mypassword";

      var sharePointHelper = new SharePointHelper.SharePointHelper();
      sharePointHelper.WriteFilesAndFolders(siteUrl, listName, username, password);
    }

我希望 SharePointHelper.dll 能够连接并从 SharePoint 获得响应。但是抛出异常One or more errors occurred. (The process has no package identity. (Exception from HRESULT: 0x80073D54))

【问题讨论】:

    标签: c# sharepoint .net-core


    【解决方案1】:

    您可以通过简单地安装TTCUE.NetCore.SharepointOnline.CSOM Nuget 包来解决此问题,以将 SharePoint 与 .NET Core 结合使用。除非您想深入了解如何解决此问题,否则没有理由遵循链接指南。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-27
      • 1970-01-01
      • 2019-08-04
      相关资源
      最近更新 更多