Friday CRM Copy/Paste Comic Relief

An odd bug recently had a colleague digging around for a while until he discovered the culprit in the form’s onload function…

Friday Copy Paste Comic Relief

Advertisements

CRM 2011 Developer Tools target location for Visual Studio 2010 vs Visual Studio 2012

The path for the targets is different for the Developer Toolkit for Visual Studio 2010 and Visual Studio 2012. This can cause errors when loading the Visual Studio project in the form of the error

The imported project “C:\Program Files (x86)\MSBuild\Microsoft\CRM\Microsoft.CrmDeveloperTools.CrmClient.targets” was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

or when attempting to deploy the CrmPackage project from Visual Studio 2010 as the error

Error connecting to CRM Server. [A]Microsoft.CrmDeveloperTools.CrmClient.Entities.Solution cannot be cast to [B]Microsoft.CrmDeveloperTools.CrmClient.Entities.Solution. Type A originates from ‘Microsoft.CrmDeveloperTools.CrmClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ in the context ‘LoadFrom’ at location ‘C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Dynamics CRM 2011 Developer Tools\1.0\Microsoft.CrmDeveloperTools.CrmClient.dll’. Type B originates from ‘Microsoft.CrmDeveloperTools, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ in the context ‘LoadFrom’ at location ‘C:\Program Files (x86)\MSBuild\Microsoft\CRM\Microsoft.CrmDeveloperTools.dll’.

or when attempting to deploy the CrmPackage project from Visual Studio 2012 as the error

Error connecting to CRM Server. [A]Microsoft.CrmDeveloperTools.CrmClient.Entities.Solution cannot be cast to [B]Microsoft.CrmDeveloperTools.CrmClient.Entities.Solution. Type A originates from ‘Microsoft.CrmDeveloperTools, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ in the context ‘LoadFrom’ at location ‘C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\Dynamics CRM 2011 Developer Tools\1.0\Microsoft.CrmDeveloperTools.dll’. Type B originates from ‘Microsoft.CrmDeveloperTools.CrmClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ in the context ‘LoadFrom’ at location ‘C:\Program Files (x86)\MSBuild\Microsoft\CRM\Microsoft.CrmDeveloperTools.CrmClient.dll’.

depending on the combination of Visual Studio version, installed Developer Toolkit version and previously installed Developer Toolkit versions.

In order to resolve any of these, make sure that the correct targets are referenced in the CrmPackage.csproj file:

  1. In Visual Studio, right click the CrmPackage project and click Unload Project.
  2. Right click on the CrmPackage project and click edit CrmPackage.csproj.
  3. Find the line starting with “<Import Project="$(MSBuildExtensionsPath32)\Microsoft\CRM\" and replace it with the correct path from the list below.
  4. Save and close the file.
  5. Right click on the CrmPackage project and click Reload Project.
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\CRM\Microsoft.CrmDeveloperTools.CrmClient.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\CRM\Microsoft.CrmDeveloperTools.12.targets" />

Current key (KeyType : CrmWRPCTokenKey) is expired. This can indicate that a key is not being regenerated correctly.

Current key (KeyType : CrmWRPCTokenKey) is expired. This can indicate that a key is not being regenerated correctly. Current Key : CrmKey(Id:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX, ScaleGroupId:00000000-0000-0000-0000-000000000000, KeyType:CrmWRPCTokenKey, Expired:True, ValidOn:01/01/2012 06:49:05, ExpiresOn:01/01/2012 06:49:05, CreatedOn:01/01/2012 06:49:05, CreatedBy:Domain\User.

Every now and then I randomly receive the error above when attempting to access CRM. Usually, restarting both the Microsoft Dynamics CRM Asynchronous Processing Service and Microsoft Dynamics CRM Asynchronous Processing Service (maintenance) resolves this but when it doesn’t, we do the following to resolve the issue:

  1. (Re)start the Microsoft Dynamics CRM Asynchronous Processing Service and Microsoft Dynamics CRM Asynchronous Processing Service (maintenance) services
  2. In a command window, run
    Microsoft.Crm.Tools.WRPCKeyRenewal.exe /R

    in the CRM Tools folder (C:\Program Files\Microsoft Dynamics CRM\Tools\ by default)

CRM2011 SOAP Money field create/update format

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:request. The InnerException message was ‘Error in line 1 position 674. Element ‘http://schemas.datacontract.org/2004/07/System.Collections.Generic:value&#8217; contains data from a type that maps to the name ‘http://www.w3.org/2001/XMLSchema:Money&#8217;. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name ‘Money’ and namespace ‘http://www.w3.org/2001/XMLSchema&#8217;.’. Please see InnerException for more details.

I recently received the error above when attempting to perform a JavaScript CreateRequest on a money field in CRM2011. I found many people experiencing the same issue without any satisfactory resolution.

The following is the correct way to format a Money field in a SOAP create or update request in CRM2011.

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">',
  <s:Body>
    <Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
      <request i:type="a:CreateRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
        <a:Parameters xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
          <a:KeyValuePairOfstringanyType>
            <b:key>Target</b:key>
            <b:value i:type="a:Entity">
              <a:Attributes>
                <a:KeyValuePairOfstringanyType>
                  <b:key>annualincome</b:key>',
                  <b:value i:type="a:Money">
                    <a:Value>1000</a:Value>
                  </b:value>
                </a:KeyValuePairOfstringanyType>
              </a:Attributes>
              <a:EntityState i:nil="true" />
              <a:FormattedValues />
              <a:Id>00000000-0000-0000-0000-000000000000</a:Id>
              <a:LogicalName>Contact</a:LogicalName>
              <a:RelatedEntities />
            </b:value>
          </a:KeyValuePairOfstringanyType>
        </a:Parameters>
        <a:RequestId i:nil="true" />
        <a:RequestName>Create</a:RequestName>
      </request>
    </Execute>
  </s:Body>
</s:Envelope>

Increase service timeout using Microsoft.Xrm.Client.dll CrmConnection class

The request channel timed out while waiting for a reply after 00:01:59.9844005. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation.

The error message above is caused by the maximum amount of time a single channel operation has to complete before a timeout fault is raised on a service channel binding being reached.

The fix for this, when not using Microsoft.Xrm.Client.dll’s CrmConnection class to connect to CRM, is well documented in several posts, (such as Dynamics CRM in the Field).

When using the Microsoft.Xrm.Client.dll’s CrmConnection class to connect to CRM, we can achieve the same thing by setting the Timeout property on the CrmConnection.

Microsoft.Xrm.Client.CrmConnection connection = new Microsoft.Xrm.Client.CrmConnection("ConnectionStringName");
connection.Timeout = new TimeSpan(0, 5, 0);
// Do something that will take longer than 2 minutes