2

Techies,

Below is the code and receiving the error "The underlying connection was closed" only in my VM not in another Virtual Machine

This is console application

string decryptedPass = "password";

        System.Security.SecureString securePass = new System.Security.SecureString();
        foreach (char c in decryptedPass)
        {
            securePass.AppendChar(c);
        }

        ClientContext clientContext = new ClientContext("siteurl");
        SharePointOnlineCredentials credentials = new SharePointOnlineCredentials("emailid", securePass);
        List oList = clientContext.Web.Lists.GetByTitle("listname");
        clientContext.Credentials = credentials;
        ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
        ListItem oListItem = oList.AddItem(itemCreateInfo);
        oListItem["Title"] = "Test Item!";
        clientContext.RequestTimeout = 100000;

        oListItem.Update();

        clientContext.ExecuteQuery();
3
  • thank you very much.. working as expected for me... Nov 21, 2018 at 12:30
  • This is not an answer to the question. Feedback should be given through comments or in Chat.
    – helb
    Nov 21, 2018 at 12:45
  • Please don't add "thank you" as an answer. Once you have sufficient reputation, you will be able to vote up questions and answers that you found helpful. - From Review
    – Gaurravs
    Nov 21, 2018 at 12:55

1 Answer 1

7

Add this to beginning of your code:

ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

Or change .Net Framework to 4.6

The issue related to default TLS settings of a web request.

Not the answer you're looking for? Browse other questions tagged or ask your own question.