question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSOM Service Exception

See original GitHub issue

Category

  • 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

  1. See code code...
  2. 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:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
subhasishmukhopadhyay2018commented, Oct 4, 2021

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.BaseDataModel1.RequestAsync(ApiCall apiCall, HttpMethod method, String operationName) at PnP.Core.Model.BaseDataModel1.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 85

I 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.

0reactions
ilovingcommented, Aug 22, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Class CsomServiceException | PnP Core SDK
CsomServiceException (ErrorType, Int32, JsonElement). Creates a CsomServiceException using the provided error type, http response code and CSOM request ...
Read more >
CSOM error: Exception from HRESULT: 0x8107140D ...
We encounter "Exception from HRESULT: 0x8107140D" error when calling SharePoint via CSOM. Following are some details: Server error code: ...
Read more >
ServerException class (Microsoft.SharePoint.Client)
Represents an exception that is thrown by the server during execution of a request sent from the client. Inheritance hierarchy. System.Object
Read more >
SharePoint CSOM not throwing expected exceptions on ...
So I went away and re-read a lot of documentation and looked over some examples, and I wondered why the exception handler never...
Read more >
SP2013 CSOM - 401 Unauthorized Exception from Server
I try to access a SharePoint 2013 Server via C# CSOM. The only thing I do is create the ClientContext , set the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found