A configuration element with the name 'MSCRM' under the 'contexts' collection does not exist.

Hi,

I was developing a ConsoleApp to connect to my Dynamics CRM 2011 deployment and when tried to instantiate the ServiceContext of my Xrm model this way:

 

var crm = new MyXrm.MyXrmServiceContext("MSCRM");

 

I got the Exception:

A configuration element with the name 'MSCRM' under the 'contexts' collection does not exist.

 

In my App.config my key was set up like this:

<connectionStrings>
  <add name="MSCRM" connectionString="Authentication Type=AD;Server=http://myserver/myorg;User ID=mydomain\user;Password=pass" />
</connectionStrings>

 

Pretty odd as I have followed the steps stated here to create a Console App from scratch.

 

So, I searched for this exception and thanks to this article I realized that there were some sections missing from my App.config file in order to properly configure the Context.

 

Solution

Just add the following sections to your .config file:

 

<configSections>
 <section name="microsoft.xrm.client" type="Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client"/>
</configSections>
<microsoft.xrm.client>
 <contexts>
  <add name="MSCRM" type="Xrm.XrmServiceContext, Xrm"/>
 </contexts>
</microsoft.xrm.client>

 

By adding those sections and running my App again, it worked like a charm!.

 

Hope it helps to save somebody else’s time,

 

PP [twitter: @pabloperalta]

UruIT Dynamix | Excellence in Dynamics CRM Nearshoring Services.

uruit_dynamix_01

No Comments