Development

Migrating apps from Microsoft.Xrm.Client to Microsoft.Xrm.Tooling

Today I had a task to migrate couple of apps that used Microsoft.Xrm.Client assemblies to new Tooling assemblies. In this article I will describe steps to use to migrate your own apps to use latest (and recommended) tools to connect to your CRM Instances from code.

Let’s assume that we have an application that uses Microsoft.Xrm.Client assembly to connect to CRM and it stores connection string to CRM in app.config file as it shown on following screenshots:

App1

 

Also I assumed that NuGet (and not your local hard drive) was as a source for referenced assemblies. To start migration open “Manage NuGet Pakages…” dialog:

App3

Update (if it is required) SDK assemblies to use latest versions available:

App4

Uninstall Microsoft.CrmSdk.Extension package:

App5

Install latest tooling package:

App6

After all operations list of your NuGet packages should look like following:

App7

Following change should be applied to code – removal of references to namespaces Microsoft.Xrm.Client and Microsoft.Xrm.Client.Services and changing of code for getting of service instance from

var connection = CrmConnection.Parse(
    ConfigurationManager.ConnectionStrings["CRMConnectionString"].ConnectionString);

var service = new OrganizationService(connection);

to

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

with adding of reference to Microsoft.Xrm.Tooling.Connector namespace.

Don’t forget to change your connection string according to this article.

If your code throws exception like

An unhandled exception of type ‘System.TypeLoadException’ occurred in Microsoft.Xrm.Tooling.Connector.dll Additional information: Could not load type ‘Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior’ from assembly ‘Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.13.8.999, Culture=neutral, PublicKeyToken=31bf3856ad364e35’.

open installed NuGet packages and downgrade Microsoft.IndentityModel.Client.ActiveDirectory to 2.28.3 version:

App8

After that your code should work fine:

App9

3 Comments

  1. Hi Andrii,

    I would add one check in your code. Once you created the CrmServiceClient instance, check the IsReady property. If the connection failed for any reason, only this property can tell you that the connection is not established

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.