I am trying to delete the remaining content type from the new button in my library. I am getting this error constantly which is weird since I am able to make the changes through the UI. Any help would be appreciated.
public async Task HideAllContentTypesInNewButtonAsync(ClientContext clientContext, string listTitle, params string[] excludedContentTypeNames)
{
List list = clientContext.Web.GetListByTitle(listTitle);
await list.EnsurePropertiesAsync(toLoad => toLoad.ContentTypes, toLoad => toLoad.ContentTypes.Include(ct => ct.Name));
var contentTypesToHide = list.ContentTypes
.Where(contentType => excludedContentTypeNames.All(name => contentType.Name != name))
.ToArray();
HideContentTypesInNewButton(list, contentTypesToHide);
list.Update();
log.LogDebug($"Hiding Content Types on list '{listTitle}'.");
await clientContext.ExecuteQueryRetryAsync();
}