web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Customer Service forum
Under review by Community Managers

Under review

Thank you for your post! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

C# connection throws "randomly" an error

Posted on by

We have c# project with .Net Framework 4.6.2 that makes a connection with Dynamics365 using CrmServiceClient to fetch/update data.

I tried both connectionstring as supplying parameters.

I upgraded to the latest NugetPackage for Xrm.Tooling

The majority of the time the code works fine, but about 10% of the time an eror is received.

The error I get (no inner exception): "One or more errors occurred. => Unauthorized Http Status Code (401) was expected in the response: Unknown error => A task was canceled.ERROR REQUESTING Token FROM THE Authentication context - General ADAL Error
Unauthorized Http Status Code (401) was expected in the response: Unknown error => A task was canceled.Unable to connect to CRM: A task was canceled.
Unauthorized Http Status Code (401) was expected in the response: Unknown error => A task was canceled.Unable to Login to Dynamics CRM
Unable to Login to Dynamics CRM"

Originally we thought this was due to issue with our capacity limitations. Both currently we are within our capacity limits, and are still facing the issue.

Anyone any suggestions on what might be the cause?

The code we use:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            //CrmServiceClient serviceTarget = new CrmServiceClient(connectionString);
            CrmServiceClient serviceTarget = new CrmServiceClient(new Uri(organizationUrl), applicationID, clientSecret,true,"");
            if ((serviceTarget.LastCrmError != null) && (serviceTarget.LastCrmError.Length > 0))

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Customer Service

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans