Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

still possible to write command line utilities w/SDK?

Posted on by 1,010

Downloaded https://code.msdn.microsoft.com/Sample-Quick-start-for-650dbcaa/view/Discussions#content

Using NuGet packages for reference assemblies

  • .Crm.Sdk.Proxy & .Xrm.Sdk                                   9.0.0.0
  • .Xrm.Sdk.Deployment & .Xrm.Sdk.Workflow        8.0.0.0
  • .Xrm.Tooling.Connector                                        2.0.0.0
  • it compiles

Verified it is a .NET framework 4.6.2 project 

Modified app.config for the QuickStart with Simplified Connection with my info for name & connectionstring (Online using Office 365 formats)

Did nothing else...  This is a current Online installation v 9.1.0.2450

I cannot connect.  Can anyone tell me what is wrong here or a better sample to start with?

CrmServiceClient conn = new Xrm.Tooling.Connector.CrmServiceClient(connectionString);

======================================
Inner Exception Level 1 :
Source  : Not Provided
Method  : Not Provided
Date    : 3/7/2019
Time    : 9:28:14 AM
Error   : Authentication Failure
Stack Trace     : Not Provided
======================================

Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Unable to Login to Dynamics CRM
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationWebProxyClient is null
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationServiceProxy is null
The application terminated with an error.
Object reference not set to an instance of an object.
Press <Enter> to exit.

thank you!

*This post is locked for comments

  • Martin Donnelly Profile Picture
    Martin Donnelly 1,010 on at
    RE: still possible to write command line utilities w/SDK?

    It's definitely the second factor.  I had the network admin shut it off for my account and succeeded.

    Now I have to figure out how to get through the second factor; how to make an app password work.

  • Verified answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: still possible to write command line utilities w/SDK?

    You could ask your sys admin to switch off two-factor authentication for the account you are using to connect to CRM.

  • Martin Donnelly Profile Picture
    Martin Donnelly 1,010 on at
    RE: still possible to write command line utilities w/SDK?

    No luck.

    thanks again.

  • Verified answer
    Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: still possible to write command line utilities w/SDK?

    the 2FA is an important information you missed.

    The easiest way is to create an application password, you can find the procedure in this post:

    d365demystified.com/.../use-azure-app-passwords-for-mfa-enabled-d365-authentication-from-console-app

    regarding the username, of course you need to use your username with the company domain if that is configured and not the onmicrosoft.com

  • Martin Donnelly Profile Picture
    Martin Donnelly 1,010 on at
    RE: still possible to write command line utilities w/SDK?

    You guys are the greatest.

    I tried Kokulan's project with both ADAL 2.22 and 2.29, both Unique Name & instance GUID and the Tls12 above and below call to the connector.

    ------------"Unable to Login to Dynamics CRM"

    Then I commented out the call and went with the signature in Guido's constructor.

    ------------"Unable to Login to Dynamics CRM"

    Let me add some other detail because this reminds me of problems with 2013 on-premise when the HomeRealmUrl wasn't being set.  When I log in manually, I am challenged for the password at the company's ADFS dialog AND by second factor authentication.  I don't see how these methods are handling that -- just wondering if that might be the concern.

    thanks so much for helping

    PS- also, my username is not of onmicrosoft.com.  It is in the company's domain.

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: still possible to write command line utilities w/SDK?

    Hi

    I use CrmServiceClient a lot in my console and other windows applications.  I found the following way of connecting seem very stable and have no issues

    Microsoft.Xrm.Tooling.Connector.CrmServiceClient CrmService = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(

                       "Your office 365 Login - Email / Username",

                       Microsoft.Xrm.Tooling.Connector.CrmServiceClient.MakeSecureString("password"),

                       "", "unique org id -> you can get it from Settings -> Customizations -> Developer Resources  -> Unique Name",

                       useUniqueInstance: true,

                       useSsl: true, isOffice365: true);

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

    var results = (WhoAmIResponse) CrmService.Execute(new WhoAmIRequest());

    if (results.Results.Any())

                   {

                       Console.WriteLine("Successfully connected to CRM");

                       Console.WriteLine($"Your user id is : {results.UserId}");

                   }

                   else

                   {

                       Console.WriteLine("The Connetion was not successful");

                   }

    I have pushed my connection code to Github and feel free to download and use this

    My github repo : https://github.com/Kokulan365/CRMServiceClientQuickStart 

    Note: Project target is .NET 4.6, you can change the target version but then you will have to update the nuget packages and find the correct matching version of the following package

    Microsoft.CrmSdk.XrmTooling.CoreAssembly : www.nuget.org/.../Microsoft.CrmSdk.XrmTooling.CoreAssembly

    Hope this helps

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: still possible to write command line utilities w/SDK?

    start with an empty console project, load the nuget package I mentioned and update all the others except ADAL (or up to 2.29)

    after in your code write directly a:

    CrmServiceClient service = new CrmServiceClient("Url=https://XXX.crmX.dynamics.com; Username=XXX@XXX.onmicrosoft.com; Password=XXX; AuthType=Office365");

    WhoAmIResponse whoAmIResponse = (WhoAmIResponse)service.Execute(new WhoAmIRequest());

    check if works and see what whoAmIResponse contains.

  • Martin Donnelly Profile Picture
    Martin Donnelly 1,010 on at
    RE: still possible to write command line utilities w/SDK?

    Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Invalid Login Information : An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.

    Both ADAL 2.29.0 and 4.5.1

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: still possible to write command line utilities w/SDK?

    pay attention to the nuget package version of ADAL (Microsoft.IdentityModel.Clients.ActiveDirectory) I normally use the 2.29 version, all the other packages you can update to the latest version. Personally I just add this one as first

    www.nuget.org/.../Microsoft.CrmSdk.XrmTooling.CoreAssembly

  • Martin Donnelly Profile Picture
    Martin Donnelly 1,010 on at
    RE: still possible to write command line utilities w/SDK?

    I kicked up the Tooling.Connector to 3.0.0.0 and added that line.

    No joy.  No difference.

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans