Upgrade to SharePoint CSOM all methods now return 400 Bad Request

Geoffrey Stephens 1 Reputation point
2022-06-28T20:32:20.613+00:00

I upgraded SharePoint CSOM to 16.1.8316.1200 in order to use ExecuteQueryWithIncrementalRetry & TryGetFileByServerRelativeUrl. Now I only get 400 Bad Request as error message, except for ClientContext GetContext(). I updated the SharePointOnlineCredentials to build the password character by character. So I figure I am missing some change to CSOM for ExecuteQueryAsync or something, but I can't find it. I am using .net Core 2.2.

public Guid? FindGuidByFileName(string spLib, string spFileName)  
        {  
            ClientContext spContext = GetClient();  
            Guid rowId = new Guid();  
            spFileName = spFileName.Trim();  
            try  
            {  
                var file = spContext.Web.GetFileByServerRelativeUrl(Path.Combine("/sites/BRSHUB/", spLib + "/" + spFileName));  
                spContext.Load(file);  
                spContext.ExecuteQueryAsync().Wait();  
  
                rowId = file.UniqueId;  
  
            }  
            catch (Exception ex)  
            {  
                _logging.LogAppError(ex, ex.Message);  
                return null;  
  
            }  
            return (rowId);  
        }  
  
public string EditDoc(string spLib, Guid rowId)  
        {  
            ClientContext spContext = GetClient();  
            string viewlink = null;  
            try  
            {  
                List targetList = spContext.Web.Lists.GetByTitle(spLib);  
                ListItem listItem = targetList.GetItemByUniqueId(rowId);  
  
                spContext.Load(listItem);  
                spContext.ExecuteQueryAsync()  
                    .Wait();  
  
                string fileLoc = listItem.FieldValues["FileRef"].ToString();  
                fileLoc = fileLoc.Replace(@"/sites/BRSHUB", "");  
  
                viewlink = spContext.Url + fileLoc;  
                return (viewlink);  
  
            }  
            catch (Exception ex)  
            {  
                _logging.LogAppError(ex, ex.Message);  
  
            }  
            return (viewlink);  
        }  
public static bool TryGetFileByServerRelativeUrl(Web web, string serverRelativeUrl,out Microsoft.SharePoint.Client.File file)  
        {  
            var ctx = web.Context;  
            try  
            {  
                file = web.GetFileByServerRelativeUrl(serverRelativeUrl);  
                ctx.Load(file);  
                ctx.ExecuteQueryAsync();  
                return true;  
            }  
            catch(Microsoft.SharePoint.Client.ServerException ex){  
                if (ex.ServerErrorTypeName == "System.IO.FileNotFoundException")  
                {  
                    file = null;  
                    return false;  
                }  
                else  
                    throw;  
            }  
        }  
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,157 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,548 questions
{count} votes