question

sachinsoni-6996 avatar image
0 Votes"
sachinsoni-6996 asked RaytheonXie-MSFT edited

Unexpected error sharepoint console application

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.



office-sharepoint-onlinesharepoint-dev
error.jpg (29.0 KiB)
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Have you tried stepping through the console application using the debugger? Where does it stop?

Honestly, the 'webCxt.RequestTimeout = System.Threading.Timeout.Infinite;' doesn't seem like a good idea.

0 Votes 0 ·

Hello @mikecantin ,

Console works fine in my dev environment, but when I move this console to prod and run exe then I encountered this error.

I have also tried to remove 'webCxt.RequestTimeout = System.Threading.Timeout.Infinite;', but unfortunately same issue is occurred

0 Votes 0 ·

I have tried to log Stack Trace and got below error.

In Client Contexthttps://xyz.sharepoint.com/sites/xyzProjects/
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.Idcrl.SharePointOnlineAuthenticationProvider.G
etIdcrlHeader(Uri url, Boolean alwaysThrowOnFailure, EventHandler`1 executingWeb
Request)
at Microsoft.SharePoint.Client.Idcrl.SharePointOnlineAuthenticationProvider.G
etAuthenticationCookie(Uri url, String username, SecureString password, Boolean
alwaysThrowOnFailure, EventHandler`1 executingWebRequest)
at Microsoft.SharePoint.Client.ClientRuntimeContext.SetupRequestCredential(Cl
ientRuntimeContext context, HttpWebRequest request)
at Microsoft.SharePoint.Client.SPWebRequestExecutor.GetRequestStream()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at XYZFileDownload.Program.Main(String[] args) in C:\xyz Migration\

0 Votes 0 ·

Hi @sachinsoni-6996 ,
would you please provide us with an update on the status of your issue?

0 Votes 0 ·

1 Answer

RaytheonXie-MSFT avatar image
1 Vote"
RaytheonXie-MSFT answered RaytheonXie-MSFT commented

Hi @sachinsoni-6996 ,

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.





· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @sachinsoni-6996 ,
I am checking to see how things are going there on this issue.

0 Votes 0 ·

Hi @sachinsoni-6996 ,
If there's anything you'd like to know, don't hesitate to ask.

0 Votes 0 ·