CSOM context.Web.Lists.GetByTitle fails on some lists

jcs.ot 1 Reputation point
2022-01-05T15:33:08.827+00:00

Hi,

My CSOM application throws ServerException when calling context.Web.Lists.GetByTitle(listName) on some lists on a sharepoint.com site (created in 2013):

Microsoft.SharePoint.Client.ServerException: List 'Categories' does not exist at site with URL 'https://xxxxx.sharepoint.com'.
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()

I use it to retrieve the list's Guid.
My app extracts all the lists' metadata from a site, I need the list Guid for tracking.

It used to work before (quite recently).
This occurs on what seems to be internal lists : Site assets, Categories, Style Library, Reusable Content, Site Pages, App Packages, Community Members and a few others

I have another developer sharepoint.com site created in 2021, I do not face this issue on the same lists names.
(CSOM api 15.0.0.0 on SharePoint online 16.0.22001.12006)

Any thoughts? Thanks!

Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,496 Reputation points Microsoft External Staff
    2022-01-06T01:34:35.743+00:00

    Hi @jcs.ot ,
    I Tested the following code and it runs well.

     var web = ctx.Web;  
                var list = web.Lists.GetByTitle("Categories");  
                ctx.Load(list);  
                ctx.ExecuteQuery();  
                Console.WriteLine(list.Id);  
                Console.ReadLine();  
    

    162693-image.png

    When you use getByTitle() you need to use the List's display name. The List 'Title' = List Display Name. The List 'Name' = List Internal Name. To find the display name look at what the list is called in the "Site Contents" page. The site url should be like https://xxxxx.sharepoint.com/sites/xxx but not https://xxxxx.sharepoint.com


    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.



  2. sadomovalex 3,636 Reputation points
    2022-01-07T15:02:36.077+00:00

    looks like you created ClientContext object with url of the root site collection (xxxxx.sharepoint.com). If you want to load list from another site collection (e.g. from xxxxx.sharepoint.com/sites/subsite), you need to create ClientContext and pass url of this exact site collection (xxxxx.sharepoint.com/sites/subsite) but not url of the root site collection. ClientContext should be created for those site collection for which you work with.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.