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.

CedricDepoortere avatar image
0 Votes"
CedricDepoortere answered BalajiAnnamalai-5734 commented

@PandeyUmesh-2690 Yes of course ;)

I'm on Windows 7 Pro SP1 64 bits, with Visual Studio 2015. My app is a C# winforms application under .net framework 4.8.

I've try to install some patch pour enable TLS 1.1 & 1.2 under Windows 7, but unsuccessfully. And same result with some modifications in the registry (SchUseStrongCrypto, SystemDefaultTlsVersions, adding TLS 1.1 & TLS 1.2 in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols...).

Here is a sample of the code :

 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    
 context = new ClientContext(string.Format("{0}/sites/{1}", Utils.Options.SPUrl, Utils.Options.SPSite));
 SecureString sstMdp = new SecureString();
    
 Utils.Options.SPPwd.ToList().ForEach(c => sstMdp.AppendChar(c));
 SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(Utils.Options.SPUser, sstMdp);
 context.Credentials = credentials;
    
 Web web = context.Web;
 context.Load(web, w => w.Title);
· 3
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 , Could you try to refer this url for help. I am not sure if you already visited this.. Let me know if this resoved your issue..

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

0 Votes 0 ·

Yes I have already applied these manipulations. And no success :/

The strange thing is that sometimes it works and others don't (it depends of the ip address behind the url). But only under Windows 7.

0 Votes 0 ·

Hello CedricDepoortere,
Where you able to resolve this problem on Windows 7 computers. I have the same issue using my C# Forms client on Windows 7 systems. They are getting this issue consistently. But same piece of code works on Windows 10 and even strage on some Windows 7 systems also.

Help on this is appreciated.

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

@CedricDepoortere , i suspect this to be a OS issue of win 7. I thin you need to find something related to OS. As most of further support and any updates are stopped to Win7 and it is not in support currenty. So any new settings, config will not updated to your OS. You should try this in Win10 in some other machine.

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.

BalajiAnnamalai-5734 avatar image
0 Votes"
BalajiAnnamalai-5734 answered

Hello CedricDepoortere,
Where you able to resolve this problem on Windows 7 computers. I have the same issue using my C# Forms client on Windows 7 systems. They are getting this issue consistently. But same piece of code works on Windows 10 and even strage on some Windows 7 systems also.

Help on this is appreciated.

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.