我在Windows Server 2012 R2数据中心计算机上的IIS上运行了.NET Core 2.2 API。它使用Nuget包Microsoft.SharePointOnline.CSOM中的DLL。但是在调用方法One or more errors occurred. (The process has no package identity. (Exception from HRESULT: 0x80073D54))
时会引发异常ClientContext.ExecuteQueryAsync()
。
我遵循以下指南:https://rajujoseph.com/getting-net-core-and-sharepoint-csom-play-nice/。我尝试了两种解决方案。首先是创建一个.NET Core Console解决方案,该解决方案将调用包含SharePoint CSOM代码的DLL。然后,我尝试从Windows Server 2012 R2数据中心计算机上的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))
。
答案 0 :(得分:0)
您只需安装TTCUE.NetCore.SharepointOnline.CSOM
Nuget程序包即可解决此问题,以将SharePoint与.NET Core一起使用。除非您想深入了解如何解决此问题,否则无需遵循链接的指南。