Unexpected error sharepoint console application

Sachin Soni 26 Reputation points
2021-06-07T16:34:14.157+00:00

Dear Expert,

I have create one console application for performing operation on sharepoint online site. but when I try to run exe, I encountered below error.

Console application main function

try
{
string siteURL = "https://xyz.sharepoint.com/sites/Projects/";
string userName = "xyz@xyz .com";
string password = "xyz@xyz ";

            ClientContext webCxt = new ClientContext(siteURL);  
            SecureString oSecurePassword = new SecureString();  
            foreach (Char c in password.ToCharArray())  
            {  
                oSecurePassword.AppendChar(c);  
            }  

            webCxt.RequestTimeout = System.Threading.Timeout.Infinite;  
            webCxt.Credentials = new SharePointOnlineCredentials(userName, oSecurePassword);  
            webCxt.ExecuteQuery();  

            getAllSubSiteUrls(siteURL, webCxt);  

            Console.WriteLine("Done");  
            Console.ReadLine();  
        }  
        catch (Exception ex)  
        {  
            Console.WriteLine(ex.Message);  
            Console.ReadLine();  
        }  

102955-error.jpg

Kindly advice.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,685 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,971 questions
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 35,466 Reputation points Microsoft Vendor
    2021-06-08T06:50:20.063+00:00

    Hi @Anonymous ,

    Since the issue related to default TLS settings of a web request. We found that the error occurs when .Net Framework version is lower than 4.6.
    Can we confirm what version of .Net Framework you are using? If your Framework version is lower than 4.6,you can take following suggestion:
    We can add following code to the beginning of our code:

    ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;  
    

    Or we can change the .Net Framework to 4.6 and above.


    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.

    1 person found this answer helpful.

Your answer

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