SharePoint CSOM ExecuteQuery throwing method missing exception

Vaishali S 1 Reputation point
2021-06-17T06:07:26.57+00:00

I have a class library project in .net framework which retrieve the list from the SharePoint using CSOM. Below is the code for it

using (Microsoft.SharePoint.Client.ClientContext spClientContext = new Microsoft.SharePoint.Client.ClientContext("url"))
{
spClientContext.Credentials = new NetworkCredential("Username", "password");
Web SpWeb = spClientContext.Web;
spClientContext.Load(SpWeb);
spClientContext.ExecuteQuery();
}

This code works fine when called from .net framework console application. I am trying to call this class library from the asp.net core web application. When its called, below exception is thrown in the ExecuteQuery

Method not found: 'Void System.Xml.XmlSecureResolver..ctor(System.Xml.XmlResolver, System.Security.PermissionSet)'

Any thoughts will be useful

Developer technologies | ASP.NET | ASP.NET Core
Microsoft 365 and Office | SharePoint | For business | Windows
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Bruce Barker 801 Reputation points
    2021-06-17T14:13:16.027+00:00

    The .netstandard version (used by core) of CSOM does not support on-premise sharepoint and standard security. It only supports azure authentication.

    using-csom-for-dotnet-standard


  2. Bruce (SqlWork.com) 81,711 Reputation points Volunteer Moderator
    2021-06-17T15:18:21.023+00:00

    core can only call .net standard, not 4.* projects. you can not trick it by having an intermediate library call a 4.8 library.

    as the .net standard version of CSOM does not support on-premise, If you need to access an on-premise sharepoint with .net core you must use the v1 REST api:

    get-to-know-the-sharepoint-rest-service

    0 comments No comments

  3. MichaelHan-MSFT 18,136 Reputation points
    2021-06-18T06:21:14.167+00:00

    Hi @Vaishali S ,

    SharePoint On-Premises CSOM does not support .net core. Only .NET Framework is supported.

    106856-image.png


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    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.


    If the response is helpful, please click "Accept Answer" and upvote it.


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.