我尝试使用 .net CORE 控制台应用程序连接到 SharePoint 列表。我收到错误消息:
System.TypeInitializationException: 'The type initializer for 'OfficeDevPnP.Core.Utilities.TokenHelper' threw an exception.'
TypeLoadException: Could not load type 'System.Web.Configuration.WebConfigurationManager' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
以下是代码示例。在 .net 标准版本中同样可以正常工作:
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core;
using System;
namespace Share_Point_POC_Core
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
string siteUrl = "https://a.b.com/sites/test";
string clientId = "33345cb6-555a-777f-9b7b-0d3aaec2222c";
string clientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx=";
using (var clientContext = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, clientId, clientSecret))
{
Web oWebsite = clientContext.Web;
ListCollection collList = oWebsite.Lists;
clientContext.Load(collList);
clientContext.ExecuteQuery();
}
}
}
}
.net core 中还有其他选择吗?