Blog Home  Home Feed your aggregator (RSS 2.0)  
Mayur's Blog - Connecting to Cutom CRM instance of Dynamics 365 threw a connection error: Metadata contains a reference that cannot be resolved
# Tuesday, January 31, 2017

Recently my online organization was upgraded to Dynamics 365 from CRM Dynamics 2016. Everything worked very well except the integration piece that used CRM SDK. The connection component threw an error message shown below.

Error details: Metadata contains a reference that cannot be resolved

The solution was to upgrade the DLL components to newer SDK components. My integration project was still using an SDK for CRM Dynamics 2016. It was quite obvious that the SDK needed an upgrade as well.

I could have downloaded the SDK using the following site. 

Please note that choosing an option of MicrosoftDynamics365SDK.exe is important. The other option is for CRM2016 version.

However, I prefer NuGet packages. I searched NuGate by "crmsdk" and chose "Microsoft Dynamics 365 Core Assemblies". As I was using integration to interact with entities and run some CRUD operations on them, I really did not need any other package. This package had required components to connect to CRM instance and to create ServiceProxy for the CRMContext. NuGate was able to download and reference the following DLLs.

Microsoft.Crm.Sdk.Proxy, Microsoft.Xrm.Sdk and Microsoft.IdentityModel

Once I upgraded to newer version everything was good except an instance of CrmConnection type. I noticed that the new SDK was missing this type. So, I quickly added my own implementation as shown below.

public class CrmConnection
        public Uri ServiceUri { get; private set; }
        public string UserName { get; private set; }
        public string Password { get; private set; }
        public ClientCredentials ClientCredentials {get; private set;}

        /// <summary>
        /// Parses a connection string and returns a new instance of CrmConnection
        /// <para>
        /// Connection string format: Url=;;Password=def;
        /// </para>
        /// </summary>
        /// <param name="connectionString"></param>
        /// <returns></returns>
        public static CrmConnection Parse(string connectionString)
            if (string.IsNullOrWhiteSpace(connectionString))
                throw new Exception("Connection string was not suppled!");

            var connectionElements = connectionString.Split(';');

            if (connectionElements.Length < 3)
                throw new Exception("Invalid connection string!");

            var crmConnection = new CrmConnection();
            crmConnection.ServiceUri = new Uri(ParseServiceUrl(connectionElements));
            crmConnection.UserName = ParseUserName(connectionElements);
            crmConnection.Password = ParsePassword(connectionElements);
            crmConnection.ClientCredentials = GetAuthenticationCredentials(crmConnection.UserName, crmConnection.Password);

            return crmConnection;

        private static string ParseServiceUrl(string[] connectionElements)
            var urlElement = connectionElements[0].Split('=');
            return urlElement[1];

        private static string ParseUserName(string[] connectionElements)
            var urlElement = connectionElements[1].Split('=');
            return urlElement[1];

        private static string ParsePassword(string[] connectionElements)
            var urlElement = connectionElements[2].Split('=');
            return urlElement[1];

        private static ClientCredentials GetAuthenticationCredentials(string userName, string password)
            var credentials = new ClientCredentials();
            credentials.UserName.UserName = userName;
            credentials.UserName.Password = password;
            return credentials;

This change only needed to build my integration project. I was able to use my existing code with this fix.

I am writing this post and hope that this may be useful to someone facing the similar issues and looking for a quick help.

Thanks a lot for vising my blog!

Tuesday, January 31, 2017 5:46:05 PM UTC  #       | 
Copyright © 2022 Mayur Bharodia. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: