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 :
Microsoft Dynamics CRM (Archived)

CrmConnection seems to fail during an attempt at using RetrieveMultiple from an OrganizationService

(0) ShareShare
ReportReport
Posted on by 105

Hi all,

I'm writing code to find the GUID of an Entity based on another unique field (old ID from previous CRM system).  This is my first code to interact with Dynamics Online CRM, so I've been trying to follow an example that would give me code like...

_DynamicsConnection = CrmConnection.Parse(_ConfigSettings.DynamicsConnectionString);


... where the string passed to the Parse method would look like...

url=blah.blah.blah.dynamics.com/.../v8.2; username=theuser; password=thepswd; authtype=Office365


Once I have the connection, I'm trying to use a QueryExpression to get the GUID of an Account (for example).  The code I'm running looks like...

string OldIDField = "name of field that holds old CRM ID";
string ConsolidationDataSourceField = "a field set up to tell us what source a record came from";
string ConsolidationDataSource = "the value of which source I care about at the moment";
string EntityString = "account";
string EntityIDField = "accountid";

ConditionExpression DataSourceMatch = new ConditionExpression();
DataSourceMatch.AttributeName = ConsolidationDataSourceField;
DataSourceMatch.Operator = ConditionOperator.Equal;
DataSourceMatch.Values.Add(ConsolidationDataSource);

ConditionExpression OldIDMatch = new ConditionExpression();
OldIDMatch.AttributeName = OldIDField;
OldIDMatch.Operator = ConditionOperator.Equal;
OldIDMatch.Values.Add("the old ID I'm looking for");

FilterExpression WhereClause = new FilterExpression();
WhereClause.Conditions.Add(DataSourceMatch);
WhereClause.Conditions.Add(OldIDMatch);

QueryExpression QueryObject = new QueryExpression(EntityString);
QueryObject.ColumnSet.AddColumn(EntityIDField);
QueryObject.Criteria.AddFilter(WhereClause);

EntityCollection QueryResult = DynamicsService.RetrieveMultiple(QueryObject); //The line that fails with an obscure exception
int ResultCount = QueryResult.TotalRecordCount;
FoundEntity = (ResultCount == 1);

if (FoundEntity)
{
	DynamicsID = QueryResult[0].Id;
}


The call to "RetrieveMultiple" is where the code fails with a strange exception that I'm not sure how to look for: "System.InvalidOperationException: 'Metadata contains a reference that cannot be resolved:".  Then it lists the URL of my Dynamics instance, except that the end of it has non-roman letters that look like middle eastern script.  Here's the QueryString portion of the URL...

BackUri=&ErrorCode=&Parm0=%0d%0a%0d%0aتفاصيل الخطأ


The exception continues by saying "Object reference not set to an instance of an object."

I'm not sure what to do next, which is why I'm writing here.  I appreciate any help that can be given.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Kevin T 9 Profile Picture
    105 on at
    RE: CrmConnection seems to fail during an attempt at using RetrieveMultiple from an OrganizationService

    One additional thing that is turning out to be important: DLL versions.  I got this running in a test project so I could isolate it, and had to try to implement the fixes in my main project.  I was having problems with that, and just now figured out what the problem is.  When you install the NuGet Packages, they change your App.Config file to declare what version to use, and it doesn't seem to match the actual version of all the DLLs by default.  If you right-click on the Microsoft.Xrm listings in your project references list that match the ones noted in your App.config, you can look at the properties of that reference and see what the actual version is.  If you match that in your config file, it should work.

  • Verified answer
    Kevin T 9 Profile Picture
    105 on at
    RE: CrmConnection seems to fail during an attempt at using RetrieveMultiple from an OrganizationService

    After a lot of work, and a lot of help from people in this forum, what seems to work for me is as follows...

    1) Use the recommended NuGet Packages...

    NuGetPackages_5F00_Working.png

    2) set up the using block to include...

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

    3) Use a connection string, specifically with the Authtype set to Office365, like...

    url=blah.blah.blah.dynamics.com; username=********; password=********; authtype=Office365

    4) Use the CrmServiceClient class like...

    CrmServiceClient MyServiceClient = new CrmServiceClient(connectionStringVariable);

    Possible important details...

    Some of the other things I did as part of the process to figuring out what the problems were included activating the Windows feature for Windows Identity Foundation, and including a line of code before the connection line in step 4 that looks like...

    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

    I don't know of those things have any bearing on whether this works now, but I wanted to list them here in case they help someone finding this forum post.

    Thanks go to many of the people in this post for suggesting most of this answer.

  • Kevin T 9 Profile Picture
    105 on at
    RE: CrmConnection seems to fail during an attempt at using RetrieveMultiple from an OrganizationService

    With experimentation, I found something that works for me in terms of making a connection without an exception.  I'll post that separate from my reply to you Michal.

  • Community Member Profile Picture
    on at
    RE: CrmConnection seems to fail during an attempt at using RetrieveMultiple from an OrganizationService

    Hi,

    I've got way around. I've got the same issue with 9.0 versio nof SDK (Core Assembly). You can go through discovery service and then pass reference to your organization service, which afterwards works fine. Let me know if you are interested I will post the code for you. Mike  

  • ashlega Profile Picture
    34,477 on at
    RE: CrmConnection seems to fail during an attempt at using RetrieveMultiple from an OrganizationService

    For 4.6.2 you may need to install a developer pack:

    www.microsoft.com/.../details.aspx

  • khoait Profile Picture
    450 on at
    RE: CrmConnection seems to fail during an attempt at using RetrieveMultiple from an OrganizationService

    .Net 4.6.1 should be OK for CRM SDK v9

  • Kevin T 9 Profile Picture
    105 on at
    RE: CrmConnection seems to fail during an attempt at using RetrieveMultiple from an OrganizationService

    I went to update my project to .net 4.6.2, and found that it's not in the list of options.  It's currently 4.6.1, which is the highest version in the list of options.  I went to install 4.6.2 thinking it was just missing from my machine, but the installer tells me it's already installed.  So I started looking for help on making it show up in the list in Visual Studio, but most of the help for a missing version of .net in the list in visual studio says you need to install it.

    Still working on this... just figured I'd provide an update.

  • Kevin T 9 Profile Picture
    105 on at
    RE: CrmConnection seems to fail during an attempt at using RetrieveMultiple from an OrganizationService

    I found something in another post about registering the DLL in the GAC.  So I tried that... and the error changed.  Maybe that's progress.  This Dynamics code is very finicky right now.  Is Microsoft working to make this better?

    As an important note: Thank you Andrew B for providing so much helpful information, and spending so much time to do it.

    I'm still working on this, and I will post what happened if I ever figure it out.  And hopefully this post is a long list of things to try for other people having this sort of problem.

  • Suggested answer
    khoait Profile Picture
    450 on at
    RE: CrmConnection seems to fail during an attempt at using RetrieveMultiple from an OrganizationService

    Hi Kevin,

    You mentioned it is Dynamics CRM online, then please double check if it is v9 or not. It may because of new change in CRM to use TLS1.2 to connect to CRM Online v9. More details here: blogs.msdn.microsoft.com/.../updates-coming-to-dynamics-365-customer-engagement-connection-security

    If it is, you'll need to:

    1. Install the CoreAssemblies for v9
    2. Switch the project to .Net 4.6.2
    3. Try again.
    4. If it doesn't work, try add the following line of code before your connection to CRM
    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

    More details on the step here: https://dyncrmexp.wordpress.com/2018/01/09/cant-connect-to-dynamics-365-customer-engagement-using-crm-sdk-v9/

    Hope it helps.

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: CrmConnection seems to fail during an attempt at using RetrieveMultiple from an OrganizationService

    To be honest I'm running out of ideas. My suggestion - try to create your app from a scratch referencing only latest and correct NuGet packages/references. I'm pretty sure that miracles do not exist.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans