I have tested the code you provide, and it runs successfully.
Could you just run the code without try catch. And check if there is still the error message
string listName = "Shared documents";
Microsoft.SharePoint.Client.List list = ctx.Web.Lists.GetByTitle(listName);
FolderCollection folders = list.RootFolder.Folders;
ctx.Load(folders);
{
ctx.ExecuteQuery();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return;
}
foreach (Folder folder in folders)
{
Console.WriteLine(folder.Name);
}
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.