Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

can't connect to dataverse in c#

(1) ShareShare
ReportReport
Posted on by

i want to connect to my dynamic 365 dataverse and by my first environment its works fine but now its not working,this is the steps that i do, i go to azure active directory and register a app with Multitenant access, and make api permissions to dataverse/dynamics and create a client secret but i get an error by trying to connect to dataverse here is my code 

static void Main(string[] args)
{
string url = "">mydomain.crm.dynamics.com";
// e.g. you@yourorg.onmicrosoft.com

string conn = $@"
Url = {url};
AuthType = ClientSecret;

AppId = myappid;
ClientSecret =my client secret;
RedirectUri = login.microsoftonline.com/.../nativeclient;
LoginPrompt=Auto;
RequireNewInstance = True";

using (var svc = new CrmServiceClient(conn))
{

WhoAmIRequest request = new WhoAmIRequest();

WhoAmIResponse response = (WhoAmIResponse)svc.Execute(request);

Console.WriteLine("Your UserId is {0}", response.UserId);

Console.WriteLine("Press any key to exit.");
Console.ReadLine();
}

and i get an error System.NullReferenceException: 'Object reference not set to an instance of an object.', by the line WhoAmIResponse response = (WhoAmIResponse)svc.Execute(request);

and by a other connection method i get a response 

The HTTP request was forbidden with client authentication scheme 'Negotiate'.

if anyone can guide me what step i missing in the app configuration 

thanks 

  • shaimaa.kamel Profile Picture
    shaimaa.kamel 15 on at
    RE: can't connect to dataverse in c#

    thank you RodRodriguez, your suggestion solve my problem.

  • Suggested answer
    shaimaa.kamel Profile Picture
    shaimaa.kamel 15 on at
    RE: can't connect to dataverse in c#

    Thank you RodRodriguez, the line "ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;" solve my problem

  • Suggested answer
    RodRodriguez Profile Picture
    RodRodriguez on at
    RE: can't connect to dataverse in c#

    Howdy mof,

    Just checking, are you using TLS 1.2 in your code as well?

    docs.microsoft.com/.../tls-1-dot-2-required-for-connectivity

    I have seen cases where all that was needed was this line added before the connection is made:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

    If this fixes the issue, please check yes :)

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: can't connect to dataverse in c#

    If my reply (or replies) answers your question take a minute and verify the answer. You can do it by clicking "Yes" at the top of the reply (or replies) under the label "Does this answer your question?"

  • mof Profile Picture
    mof on at
    RE: can't connect to dataverse in c#

    thanks a much,yes i forgot from this important step

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: can't connect to dataverse in c#

    Hello,

    Did you add App User to the instance you're trying to connect to?

  • mof Profile Picture
    mof on at
    RE: can't connect to dataverse in c#

    thanks for your reply , i get this in svc.LastCrmError

    Invalid Login Information : The HTTP request was forbidden with client authentication scheme 'Anonymous'.

    The HTTP request was forbidden with client authentication scheme 'Anonymous'. => The remote server returned an error: (403) Forbidden.Unable to Login to Dynamics CRM

    Unable to Login to Dynamics CRM

  • mof Profile Picture
    mof on at
    RE: can't connect to dataverse in c#

    its works fine in the other enviorement

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: can't connect to dataverse in c#

    Oh, I use this stuff almost the last decade and had no need for it. New day, new lesson. Thanks, Guido Preite!

  • Guido Preite Profile Picture
    Guido Preite 54,073 Moderator on at
    RE: can't connect to dataverse in c#

    yes, single quotes are allowed (mostly for the scenario when the password/clientsecret contains a semicolor or equals sign

Under review

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

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,309 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans