Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

Error while connecting .NET core console app with d365 crm on-prem.

Posted on by 25

Hello everyone,

I have already connected d365 CRM online with the .net core console app using client id, clients secret, and organization URI. But it is throwing an error on connecting with on-prem.

here is the error.

Microsoft.PowerPlatform.Dataverse.Client.Utils.DataverseConnectionException
HResult=0x80131500
Message=Failed to connect to Dataverse
Source=Microsoft.PowerPlatform.Dataverse.Client
StackTrace:
at Microsoft.PowerPlatform.Dataverse.Client.ServiceClient.CreateServiceConnection(Object externalOrgServiceProxy, AuthenticationType requestedAuthType, String hostName, String port, String orgName, NetworkCredential credential, String userId, SecureString password, String domain, String Geo, String claimsHomeRealm, Boolean useSsl, Boolean useUniqueInstance, OrganizationDetail orgDetail, String clientId, Uri redirectUri, PromptBehavior promptBehavior, OrganizationWebProxyClient externalOrgWebProxyClient, String certificateThumbPrint, StoreName certificateStoreName, X509Certificate2 certificate, Uri instanceUrl, Boolean isCloned, Boolean useDefaultCreds, Version incomingOrgVersion, ILogger externalLogger)
at Microsoft.PowerPlatform.Dataverse.Client.ServiceClient..ctor(Uri instanceUrl, String clientId, String clientSecret, Boolean useUniqueInstance, ILogger logger)
at DOHTestCoreConApp.Program.crmConnection() in C:\DOH PRP\Code\DOHTestCoreConApp\DOHTestCoreConApp\Program.cs:line 23
at DOHTestCoreConApp.Program.Main(String[ args) in C:\DOH PRP\Code\DOHTestCoreConApp\DOHTestCoreConApp\Program.cs:line 11

This exception was originally thrown at this call stack:
[External Code

Inner Exception 1:
AggregateException: One or more errors occurred. (Need a non-empty authority (Parameter 'Authority'))

Inner Exception 2:
ArgumentNullException: Need a non-empty authority (Parameter 'Authority')

and here is the code.

 string SoapOrgServiceUri = "http://crm/XRMServices/2011/Organization.svc";
 Uri serviceUri = new Uri(SoapOrgServiceUri);

string client_id = "****";
string client_sec = "****";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var cdsClient = new ServiceClient(serviceUri, client_id, client_sec, true);

  • Suggested answer
    kmish Profile Picture
    kmish 50 on at
    RE: Error while connecting .NET core console app with d365 crm on-prem.

    Data8.PowerPlatform.Dataverse.Client has made my day.

    markcarrington.dev/.../

  • Suggested answer
    Wahaj Rashid Profile Picture
    Wahaj Rashid 11,319 on at
    RE: Error while connecting .NET core console app with d365 crm on-prem.

    Hi,

    I have not tried .Net Core SDK with on-premise.

    You can try registering your on-premise app first:

    docs.microsoft.com/.../walkthrough-register-app-active-directory

  • Khubaib0078 Profile Picture
    Khubaib0078 25 on at
    RE: Error while connecting .NET core console app with d365 crm on-prem.

    Sorry, it is necessary to use .net core. Can't change that.

  • Suggested answer
    Wahaj Rashid Profile Picture
    Wahaj Rashid 11,319 on at
    RE: Error while connecting .NET core console app with d365 crm on-prem.

    Hi,

    Yes, that is the reason you need to access it using CRMServiceClient (.Net Framework).

    You can access an on-premise environment, without registering an App (and using AD (or NTLM) Authentication).

  • Khubaib0078 Profile Picture
    Khubaib0078 25 on at
    RE: Error while connecting .NET core console app with d365 crm on-prem.

    Only Client Secret and OAuth can be used to connect .net core with CRM.

  • Khubaib0078 Profile Picture
    Khubaib0078 25 on at
    RE: Error while connecting .NET core console app with d365 crm on-prem.

    The problem is I don't get redirect URI on registering the app, that's why I am using client secrect and I am using .net core.

  • Suggested answer
    Wahaj Rashid Profile Picture
    Wahaj Rashid 11,319 on at
    RE: Error while connecting .NET core console app with d365 crm on-prem.

    Hi,

    Thank you for your query.

    For On premise, you need to connect using Authentication Type: AD, which is not supported with ServiceClient.

    I believe this is meant for only Datavers (Online) version.

    For On-premise, you need to use .Net Framework, please look into following article:

    https://docs.microsoft.com/en-us/powerapps/developer/data-platform/org-service/quick-start-org-service-console-app

    Your AD Connection string should be something like:

    string url = ;
    
    string conn = $@"
    Url = {url};
    AuthType = AD;
    RequireNewInstance = True";
    
    

    You can add username and password as well.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans