question

ChadCarey-6325 avatar image
0 Votes"
ChadCarey-6325 asked BalajiAnnamalai-5734 commented

C# + Microsoft.Sharepoint.Client = Underlying connection cwas closed

I am trying to figure out why all of a sudden, with in the last 2 weeks or so that any of our code that used Microsoft.Sharepoint.Client CSOM to do SP stuff is now failing with the generic "the underlying connection was closed....."

We are using the newest version of ASP.Net with C#. Whatever the newest version of the DLLs are from NuGet.

Problem only happens on our windows 2012 R2 servers. If I run the code from my local machine it always works. TLS 1.2 is enabled in the registry for both client and server.

How do I resolve them?

office-sharepoint-online
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.

ChadCarey-6325 avatar image
0 Votes"
ChadCarey-6325 answered

this is connecting to sharepoint online not an on prem instance.

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.

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered MichaelHan-MSFT edited

Hi @ChadCarey-6325 ,

Are you using SharePoint app only to authenticate with the function PnP.Framework.AuthenticationManager().GetACSAppOnlyContext?

If so, it could be related with the cyphers. I have answered the same issue here: https://docs.microsoft.com/en-us/answers/questions/401398/sharepoint-add-in-failure-to-acquire-app-only-toke.html?childToView=406335#answer-406335

Make sure the server supports one of supported cyphers:

  • TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384

  • TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256

  • TLS_DHE_RSA_WITH_AES_256_GCM_SHA384

  • TLS_DHE_RSA_WITH_AES_128_GCM_SHA256


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.


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.

ChadCarey-6325 avatar image
0 Votes"
ChadCarey-6325 answered

no sharepoint app needed to log in with CSOM.

This doesn't happen every time but most of the time.

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.

ChadCarey-6325 avatar image
0 Votes"
ChadCarey-6325 answered

What do you do if those listed cyphers aren't even in the list of selectable ones from the tool?

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.

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered

Hi @ChadCarey-6325 ,

Per my test, these cyphers are listed in the tool:

99989-image.png



image.png (97.2 KiB)
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.

PandeyUmesh-2690 avatar image
0 Votes"
PandeyUmesh-2690 answered

We are also facing the same issue in a console application while using CSOM to call sharepoint online. While we are using user ID and password to fetch the data and sharepointonlinecredential class to get authentication.

Is anyone got this issue resolved yet.

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.

PandeyUmesh-2690 avatar image
0 Votes"
PandeyUmesh-2690 answered

ctx.Credentials = new SharePointOnlineCredentials(userName, pwd);
ctx.RequestTimeout = Timeout.Infinite;

                 Web web = ctx.Web;
                 ctx.Load(web);
                 ctx.ExecuteQuery();

Error appears when code executes to ctx.ExecuteQuery();.

Detailed Error:
The underlying connection was closed: An unexpected error occurred on a send.
System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

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.

TabrejMohammadContractor-0913 avatar image
0 Votes"
TabrejMohammadContractor-0913 answered TabrejMohammadContractor-0913 published

Hi,

you can try check the below url to create new key on registry which may resolve the issue.

https://docs.microsoft.com/en-us/mem/configmgr/core/plan-design/security/enable-tls-1-2-client#configure-for-strong-cryptography

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.

CedricDepoortere avatar image
0 Votes"
CedricDepoortere answered

Hi,

Same problem here. Sometimes it works, other times it doesn't: /

My application is running on Windows 7 (sorry!)

I noticed that when that doesn't work, the site I want to query responds to the ping with the address 13.107.136.9.
When this works, the address returned by the ping is 40.108.231.25.

In Windows 10, both addresses work.

Via WireShark I see an RST, ACK response right after the ACK response.

If anyone has a solution thanks in advance!

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.

PandeyUmesh-2690 avatar image
0 Votes"
PandeyUmesh-2690 answered

@CedricDepoortere , if you could describe what is environment, which language and other detials may be we can help you. As we resolved this issue for one of the console application running .NEt Frameowrk on windows 10.

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.