CSOM Service Exception
See original GitHub issueCategory
- Bug
Getting “CSOM Service Exception” error when trying to update existing SharePoint list item.
using System; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using PnP.Core.QueryModel; using PnP.Core.Services; using PnP.Core.Services.Builder.Configuration; using PnP.Core.Auth.Services.Builder.Configuration; using System.Linq; using PnP.Core.Auth; using PnP.Core.Model.SharePoint;
namespace PnPCoreSDK_ListItemUpdate { class Program { static async Task Main(string[] args) { var host = Host.CreateDefaultBuilder() .ConfigureLogging((hostingContext, logging) => { logging.AddEventSourceLogger(); logging.AddConsole(); }) .ConfigureServices((hostingContext, services) => { services.AddPnPCore(); services.Configure<PnPCoreOptions>(hostingContext.Configuration.GetSection(“PnPCore”)); services.AddPnPCoreAuthentication(); services.Configure<PnPCoreAuthenticationOptions>(hostingContext.Configuration.GetSection(“PnPCore”)); }) // Let the builder know we’re running in a console .UseConsoleLifetime() // Add services to the container .Build();
await host.StartAsync();
using (var scope = host.Services.CreateScope())
{
var pnpContextFactory = scope.ServiceProvider.GetRequiredService<IPnPContextFactory>();
using (var context = await pnpContextFactory.CreateAsync(new Uri("<SharePoint Site Url>")))
{
var linksList = await context.Web.Lists.GetByTitleAsync("<list title>");
var viewXml = $@"<View>
<Query>
<Where>
<Eq>
<FieldRef Name='ID' />
<Value Type='Number'>1</Value>
</Eq>
</Where>
</Query>
</View>";
await linksList.LoadItemsByCamlQueryAsync(new CamlQueryOptions()
{
ViewXml = viewXml,
DatesInUtc = true
});
int count = 0;
int total = linksList.Items.AsRequested().ToList().Count;
Console.WriteLine($"Found total item {total}");
foreach (IListItem linksListItem in linksList.Items.AsRequested())
{
count++;
Console.WriteLine($"Updating - {count} of total {total} ID : {linksListItem.Id.ToString()}");
try
{
linksListItem["SiteName"] = "newSiteName";
await linksListItem.UpdateOverwriteVersionAsync();
}
catch (Exception ex)
{
Console.WriteLine("Error " + ex.Message + "\n" + ex.StackTrace);
}
}
Console.WriteLine("Done");
}
}
}
}
}
Steps to reproduce
- See code
code...
- Execute it and throw exception
Expected behavior
Item should be updated
Environment details (development & target environment)
- SDK version: PnP.Core.Auth 1.3.0
- OS: Windows 10
- SDK used in: .Net Core 3.1
- Framework: .NET Core v3.x
- Browser(s): NA as console app
- Tooling: Visual Studio 2019
- Additional details: Item creation and deletion works fine. Update also works fine with ‘Item’ content type. Thanks for your contribution! Sharing is caring.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
Hi Bert,
Here is the error message below.
Error HttpResponseCode: 200 Message: Unknown Error ClientRequestId: 3af6f49f-8001-0000-cffe-4e829c8d18cb ErrorTypeName: “Microsoft.SharePoint.Client.UnknownError”
PnP.Core.CsomServiceException: CSOM service exception at PnP.Core.Services.BatchClient.ProcessCsomBatchResponse(CsomBatch csomBatch, String batchResponse, HttpStatusCode statusCode) at PnP.Core.Services.BatchClient.ExecuteCsomBatchAsync(Batch batch) at PnP.Core.Services.BatchClient.ExecuteBatch(Batch batch) at PnP.Core.Model.BaseDataModel
1.RequestAsync(ApiCall apiCall, HttpMethod method, String operationName) at PnP.Core.Model.BaseDataModel
1.RawRequestAsync(ApiCall apiCall, HttpMethod method, String operationName) at PnP.Core.Model.SharePoint.ListItem.UpdateOverwriteVersionAsync() at PnPCoreSDK_ListItemUpdate.Program.Main(String[] args) in C:\Users\subhasishm.FAREAST\Downloads\PnPCoreSDK-Hello-World\PnPCoreSDK-Hello-World\Program.cs:line 85I see this is happening for this list and when an item is created using a custom content type. It works fine with OOTB item content type. The issue only happens during update not new item creation or deletion.
Also we can create and update items using SPFx and PnP Powershell with no issues. Looks like some inconsistency in update in the api side; I am happy to provide more information if you needed.
From: Bert Jansen @.> Sent: Thursday, September 30, 2021 11:43 AM To: pnp/pnpcore @.> Cc: subhasishmukhopadhyay2018 @.>; Mention @.> Subject: Re: [pnp/pnpcore] CSOM Service Exception (#559)
Hi @subhasishmukhopadhyay2018https://github.com/subhasishmukhopadhyay2018 : can you also do ex.ToString() and share that output here? It will contain more details about why this goes wrong. I’m suspecting some other fields in the list are somehow causing this…can you reproduce this on any list or only one a specific one?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/pnp/pnpcore/issues/559#issuecomment-930816701, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ATHY5GFJYDU5EOTVTXZFDX3UEP52HANCNFSM5FBKQ3AA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
I am running into this problem with Add-PnPPageSection and Set-PnPPage, but it happens completely randomly.
And it’s not just these. Sometimes I run Get-PnPTenantSite and it “can’t find the site” despite the fact that I literally just made it.
These are clearly backend failures with Sharepoint itself. The only question is, what’s the best way to deal with them? It’s irritating that I need to flood my scripts with try/catch blocks and various other retry patterns because Sharepoint is so unreliable.