Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

OAuth CrmServiceClient CRM connection issues

(0) ShareShare
ReportReport
Posted on by 255

Hi

I can't connect to CRM online with OAuth CrmServiceClient.

Whenever I try it times out. I'm going mad with this!!!

My test code is below.

Does the user need particular permissions or anything?

(.Net version 4.6.2)

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Tooling.Connector;
using System;


public partial class  c2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        string ConnectionString = "AuthType=OAuth;Username=xxx@xxx.com;Password=xxx;Url=https://xxx.crm4.dynamics.com;AppId=51f81489-12ee-4a9e-aaae-a2591f45987d;RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;LoginPrompt=Never";

        CrmServiceClient svc = new CrmServiceClient(ConnectionString);

        if (svc.IsReady)
        {
            var myContact = new Entity("contact");
            myContact.Attributes["lastname"] = "Test";
            myContact.Attributes["firstname"] = "User1";
            svc.Create(myContact);
        }
    }
}

  • RE: OAuth CrmServiceClient CRM connection issues

    good! enjoy your time :)

  • Stuie Profile Picture
    Stuie 255 on at
    RE: OAuth CrmServiceClient CRM connection issues

    All done. thanks for all your help!

  • Stuie Profile Picture
    Stuie 255 on at
    RE: OAuth CrmServiceClient CRM connection issues

    Fixed that by using ClientSecret instead but now getting NullReference when executing service.RetrieveMultiple.

           CrmServiceClient service = new CrmServiceClient(ConfigurationManager.ConnectionStrings["CrmClient"].ConnectionString);

    EntityCollection ec = service.RetrieveMultiple(QEcontact);

  • Stuie Profile Picture
    Stuie 255 on at
    RE: OAuth CrmServiceClient CRM connection issues

    Now seeing this;

    Error occurred:ERROR REQUESTING Token FROM THE Authentication context - General ADAL Error user_interaction_required: One of two conditions was encountered: 1. The PromptBehavior.Never flag was passed, but the constraint could not be honored, because user interaction was required. 2. An error occurred during a silent web authentication that prevented the http authentication flow from completing in a short enough time frameUnable to connect to CRM: user_interaction_required: One of two conditions was encountered: 1. The PromptBehavior.Never flag was passed, but the constraint could not be honored, because user interaction was required. 2. An error occurred during a silent web authentication that prevented the http authentication flow from completing in a short enough time frame user_interaction_required: One of two conditions was encountered: 1. The PromptBehavior.Never flag was passed, but the constraint could not be honored, because user interaction was required. 2. An error occurred during a silent web authentication that prevented the http authentication flow from completing in a short enough time frameUnable to Login to Dynamics CRM Unable to Login to Dynamics CRM

  • RE: OAuth CrmServiceClient CRM connection issues
    [quote user="Stuie"

    Now giving this error

    Error occurred:One or more errors occurred. => Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.ERROR REQUESTING Token FROM THE Authentication context - General ADAL Error One or more errors occurred. => Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.One or more errors occurred. => Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.Unable to connect to CRM: Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. One or more errors occurred. => Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.Unable to Login to Dynamics CRM Unable to Login to Dynamics CRM

    [/quote

    almost done.

    you have check web.config exist this code. and check system.net.http reference added in your project.

      
        
          
          
            
            
          
        
      
    

    Add Reference Any version if you write upper code.

    pastedimage1649772382297v2.png

    or Download from Nuget

    pastedimage1649772176660v1.png

  • Stuie Profile Picture
    Stuie 255 on at
    RE: OAuth CrmServiceClient CRM connection issues

    Now giving this error

    Error occurred:One or more errors occurred. => Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.ERROR REQUESTING Token FROM THE Authentication context - General ADAL Error One or more errors occurred. => Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.One or more errors occurred. => Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.Unable to connect to CRM: Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. One or more errors occurred. => Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.Unable to Login to Dynamics CRM Unable to Login to Dynamics CRM

  • RE: OAuth CrmServiceClient CRM connection issues
    [quote user="Stuie"

    Could not load type 'WebApplication1.WebForm1'.

    [/quote

    can you develop using visual studio and .net framework?

    seems using ASP NET (old version)

    can you write security protocol before connect ?

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
    
    var svc = new CrmServiceClient(conn);

    or you keep get error

    using this code and share the exception message

    svc.LastException

  • Stuie Profile Picture
    Stuie 255 on at
    RE: OAuth CrmServiceClient CRM connection issues

    OK ive incorporated your code into my project after successfully connecting using your project but all I get is a hanging attempt to connect.

  • Stuie Profile Picture
    Stuie 255 on at
    RE: OAuth CrmServiceClient CRM connection issues

    Could not load type 'WebApplication1.WebForm1'.

  • Stuie Profile Picture
    Stuie 255 on at
    RE: OAuth CrmServiceClient CRM connection issues

    Hi. I too was able to create a simple web project and using CrmServiceClient I was able to connect but when I then start to add the rest of my project files and references, it stops working.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans