尝试 运行 提供商托管的应用程序到 SharePoint online 时出错

error while trying to run the provider hosted app to SharePoint online

最近我正在尝试创建一个提供商托管的应用程序来在线共享积分。 我已经配置了 Azure Web 应用程序并创建了应用程序并将其发布到在线共享点。我现在可以在 SharePoint 在线应用程序目录中看到该应用程序。但是当我尝试 运行 应用程序时,它抛出以下错误。

System.IO.FileNotFoundException: msoidcliL.dll at Microsoft.SharePoint.Client.Idcrl.IdcrlNativeMethodsSelector..ctor(String dllPath) at Microsoft.SharePoint.Client.Idcrl.ManagedIdcrl.get_IdcrlNativeMethods() at Microsoft.SharePoint.Client.Idcrl.ManagedIdcrl.EnsureInited() at Microsoft.SharePoint.Client.Idcrl.ManagedIdcrl.LogonIdentity(String username, SecureString password) at Microsoft.SharePoint.Client.Idcrl.SharePointOnlineAuthenticationProvider.Logon(String username, SecureString password) at Microsoft.SharePoint.Client.SharePointOnlineCredentials..ctor(String username, SecureString password) at SharePointApp5Web.Default.Page_Load(Object sender, EventArgs e) 

代码

 var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);

        try
        {
            string str;
            using (ClientContext ctx = new ClientContext("https://mydomain.sharepoint.com/sites/General/Community%20Portal/HR/Acknowledgements"))
            {
                ctx.Credentials = new Microsoft.SharePoint.Client.SharePointOnlineCredentials("myname@domain.com", ConvertToSecureString("password"));

                Web myweb = ctx.Web;
                List myList = myweb.Lists.GetByTitle("Timesheet Administration Policy");
                ListItemCreationInformation ItemCreationInfo = new ListItemCreationInformation();

                CamlQuery camlQuery = new CamlQuery();
                camlQuery.ViewXml =
                    @"<Query>
                   <Where>
                      <Neq>
                         <FieldRef Name='ID' />
                         <Value Type='Counter'>946</Value>
                      </Neq>
                   </Where>
                </Query>";


                Microsoft.SharePoint.Client.ListItemCollection listItems = myList.GetItems(camlQuery);
                ctx.Load(listItems);
                ctx.ExecuteQuery();


                    foreach (Microsoft.SharePoint.Client.ListItem listItem in listItems.ToList())
                    {

                        try
                        {
                            Response.Write(listItem["Email_x0020_Address"].ToString().Trim());

                        }
                        catch (Exception ex)
                        {
                            Response.Write(ex.ToString());
                        }
                    }
                }
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }

CSOM dll 似乎有问题。请安装最新的 CSOM 在线版本,然后 deploy/publish 您的代码。

转到Visual studio中的项目引用,右键打开Manage Nuget packages如下:

搜索 CSOM 并安装 Microsoft.SharePointOnline.CSOM

或者,您也可以从下面提到的 Microsoft 下载 link 下载它并手动添加引用:

SharePoint Online Client Components SDK

此外,确保 .NET 框架面向 v4.5 并且平台目标设置为 Any CPU。另外,确保引用了 v16 程序集。

此外,在 ctx.Credentials 行下方添加以下代码:

ctx.AuthenticationMode = ClientAuthenticationMode.Default;