Microsoft Dynamics CRM 2011

Microsoft Dynamics CRM 2011
Showing posts with label CRM 2011. Show all posts
Showing posts with label CRM 2011. Show all posts

Wednesday, July 18, 2018

Dynamics CRM Errors when importing unmanaged solution

In this article we see Step by step How to fix Dynamics CRM Errors when importing unmanaged solution , in both CRM 2011 and CRM 2013 .
Several errors can be thrown by Microsoft Dynamics CRM while importing an unmanaged solution from test to production environments, such as "This import has failed because a different entity with the identical name" , or "Field Is Not Unique"...
Usually the causes are differences of schema between fields or entities.

First of all, try to check this 2 things:

1) Schema name and name : have the fields/entities EXACTLY (letter capitalization) the same schema names? (  new_MyField < > new_myfield ) 

2) Schema data types: have the fields/entities EXACTLY the same type? (nvarchar = nvarchar, int = int)

We'll see here in only 10 minutes how to perform a search for the DYNAMICS CRM API web service error codes , such as "0x80044150" or "0x80041a06" , for example :

Errors when importing unmanaged solution
Dynamics CRM Errors importing unmanaged solution


How to fix Dynamics CRM Errors when importing unmanaged solution


Usually, you will get this kind of error while importing a CRM solution:

Dynamics CRM Errors when importing unmanaged solution


The steps are usually as following:
0) open the importing error file and make a search for "0x" to get the error!!!
1) get the hexadecimal error code for the Entity and delete the hexadecimal prefix "0x"
2) search the web for the error without the "0x" prefix
3) re-build any custom Field which has an schema name ("new_myfield") difference
4) re-build any custom Field which has a type difference


1) Step #0: open the log file to find the error :

Dynamics CRM Errors when importing unmanaged solution



2) Step #1: get the hexadecimal Error Code & delete its "0x" prefix :


Dynamics CRM when importing unmanaged solution




3) Step #2: search the Web for the code but without the prefix "0X":


Make a search for "DYNAMICS CRM API web service error codes" , and append the error code:

CRM Errors when importing solution





Dynamics CRM Errors when importing unmanaged

Remember: as long as Microsoft Dynamics CRM uses GUIDs , and they are different between a development environment to a production environment, the only way it has to identify an Entity is its schema name and its type !!!!!!



Happy CRM.....

      by Carmel Schvartzman


כתב: כרמל שוורצמן

Tuesday, April 21, 2015

How to use Tracing in CRM 2011-2013 Plugins and Workflows

In this article we describe Step by step How to use Tracing in CRM 2011-2013 Plugins and Workflows in C# in 5 minutes.
Since CRM Plugins and Workflows are deployed on web servers after the development reaches the release stage , it is usually very helpful to include tracing in your code in profusion, not only in error cases, at least when you are putting to the test new developments .
CRM 2011-2013 allows you to include tracing galore:
How to use Tracing in CRM 2011-2013 Plugins and Workflows



How to use Tracing in CRM 2011-2013 Plugins and Workflows



Phase 1: use the GetExtension() method from the "context" at your plugin-workflow:
Tracing in CRM 2011-2013 Plugins and Workflows


Since this is a generic C# Dot.Net method, use the ITracingService interface to get the tracing service from the context.


Phase 2: Send the ITracingService to any method where you intend to log information using tracing:

CRM 2011-2013 Plugins and Workflows

For example:

How to use Tracing in CRM


Phase 3: inside the plugin's methods, call the ITracingService's Trace() method to send messages to the tracing:

How to use Tracing in CRM 2011-2013


In case of error, CRM will display an alert showing the tracing:


How to use Tracing in CRM 2011-2013 Plugins and Workflows


That's all...Enjoy Dynamics CRM

by Carmel Schvartzman

כתב: כרמל שוורצמן


    Tuesday, November 11, 2014

    "Could not load file or assembly Microsoft.IdentityModel" exception in Dynamics CRM 2013 (2011)


    1. In this walkthrough we will learn how to take care of the "Could not load file or assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies" error in a Dynamics CRM 2013 (2011) related .Net application .

    The "Could not load file or assembly Microsoft.IdentityModel" exception


    1. Dynamics CRM 2011 - 2013 uses the Windows Identity Foundation in order to contact the Organization Web Service. 
    2. The "Could not load file or assembly 'Microsoft.IdentityModel" Exception's message tells us explicitly of the need of reference and loading an "assembly".
    3. However, the error message is misleading, since you wont have to reference certain assembly from your .Net project. Instead, you'll need to install a Windows's update : .
    4. First browse to the Microsoft Identity Foundation download web page  :

      "Could not load file or assembly Microsoft.IdentityModel" exception
    5. Check that your machine complains with the Microsoft Identity Foundation 's System Requirements.
    6. Check the "Install Instructions" to see which package is appropriate for your machine :
      "Could not load file or assembly Microsoft.IdentityModel" exception 1
      And download the one you need (the 64 bit package, for instance):

    7. "Could not load file or assembly Microsoft.IdentityModel" exception 2
    8. Locate the downloaded package and open it:

    9. Then follow the install steps until you finish the setup (notice that this is an update for Windows, the update KB974405):









    10. After you finish the installation, you will be tempted to follow the leads from the Exception message , "Could not load file or assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies" , by adding some assembly to your project:



      But, where is the assembly?
    11. Remember, this is an update for Windows , and not an assembly: the error message can mislead us ...
      You don't have to search some assembly, neither close-open your Visual Studio nor restart your machine. Actually, you don't have to do anything: just run again your .Net application, and you'll find that now is working perfectly.
    12. In this walk-through we've review how to fix the "Could not load file or assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies" error in a Dynamics CRM 2013 (2011) related .Net application .
    13. That's all...Enjoy Dynamics CRM

      by Carmel Schvartzman

      כתב: כרמל שוורצמן


    Wednesday, April 30, 2014

    "The given key was not present in the dictionary" KeyNotFoundException Exception in CRM 2013 Plugin or custom Workflow

    by Carmel Shvartzman

    In this walkthrough we will learn how to take care of the "The given key was not present in the dictionary" - "KeyNotFoundException" error in a Dynamics CRM 2013 (2011) Plug-in or custom Workflow.
    1. A disadvantage of using late-binding when coding a CRM 2013 Plugin is, you shoud be very careful with the attributes names, since there is no compile time checking. 
    2. Specially when you have added a new field to an entity, and you get the "The given key was not present in the dictionary" Exception, you'll be prone to think something is not good with the new field definitions, or worse , the Organization Web Service is not recognizing the new field, or even worse, the Web Service needs to be reset to render the field, or may be you'd be desperately thinking to restart the CRM server to refresh the Web Service.
    3. That's because the error message by CRM may be misleading : you may be expecting that, in case your new field contains a null value, CRM Retrieve() or RetrieveMultiple() or Execute() will locate the field attribute, and fetch a NULL value for it. But CRM wouldn't : it WILL NOT INCLUDE THE KEY IN THE ATTRIBUTE'S DICTIONARY UNLESS IT CONTAINS A VALUE : if your field is not a REQUIRED field, you must code a checking for the presence or absence of the field.
    4. For instance, let's say you've added a new field named "new_test", and inside your Plug In you fetch it as follows:
    5. If the present entity has a NULL value in it , you'll be faced to the "The given Key..." exception:
    6. First think you'll want to check, is whether you requested for the field in the ColumnsSet:
    7. But that's not the problem. You did indeed. However, the "new_test" field attribute IS NOT THERE:

    8. That's because CRM WILL NOT INCLUDE THE KEY IN THE ATTRIBUTE'S DICTIONARY UNLESS IT CONTAINS A VALUE (meaning it was SET or UPDATED).
    9. You MUST perform a check for the field existence, but not a NULL check as this:
    10. You should instead use the ContainsKey(string) method from the Collection, for EVERY NO REQUIRED FIELD on the Entity:



      Hoping it helped you.
      That's all...Enjoy Dynamics CRM


      כתב: כרמל שוורצמן

    Tuesday, December 24, 2013

    How to debug a CRM 2011 Custom Plugin / Workflow

    by Carmel Schvartzman

    1. In this walkthrough we will learn Step - By - Step How to debug a custom  Plugin / Workflow in Dynamics CRM 2011. Once you have developed your custom workflow, you deploy the assembly containing the plugin in the CRM web server, and register it with the Plugin Registration Tool of the CRM 2011 SDK.
    2. The problem is, every time you change the code, and recompile the assembly, you must redeploy it and the process of debugging-compiling-deploying-registering is very time-consumer and this cycle restarts for every bug and every update you may want to do.
    3. The best and quickest way of debugging-redeploying  your plugin is inside the CRM server itself. If you upgrade your code from inside the CRM web server, the process of debug and redeploy it will be far more quicker. You can also perform the testings against a test Organization.
    4. First, check whether or not Visual Studio 2010-2012 is installed in the CRM web server. If it doesn't, install it.
    5. Next, copy the workflow solution to the CRM server, or else develop entirely your  Plugin from the Visual Studio in the CRM server.
    6. Provided you have already built your workflow project, you must deploy it in the CRM server. You copy the assembly from the BIN folder of your project, to the special folder where CRM expects the plugins to be ( Microsoft Dynamics Crm\Server\Bin\Assemply ). Then, open the Plugin Registration Tool, and select "Register New Assembly":
    7. How to debug a CRM 2011 Custom Plugin / Workflow
    8. Specify the assembly location:
    9. Select the "Database" option:
    10. Now that your plugin has been registered, you can debug it this way: switch to the workflow project opened in the Visual Studio installed on the CRM web server:
    11. On the "Debug" tab, select "Attach to Process":
    12. Now select the two "CrmAsynchService.exe" which are running on the CRM server. Those are the services which take care of the plugins, workflows, and every asynchronic processes being run on the CRM 2011:
    13. Press the "Attach" for each one of the processes:
    14. Now debug your workflow at your ease. Open your CRM account and call the workflow which calls your custom plugin/workflow. Wait some seconds (it's an asynchronic process so CRM will decide by its own when to run your plugin) and you'll see that the breakpoints you have set on your code will be reached.
    15. Let's say that you've found a bug or you need to upgrade the code. You compile it and next you must redeploy the assembly and update the registration of the plugin, and debug again.  Therefore, open the BIN folder of your workflow project, and copy the .dll:
    16. Now open the folder where are stored the CRM custom plugins ( Microsoft Dynamics Crm\Server\Bin\Assemply ):
    17. Paste there the assembly. Next, open the Plugin Registration Tool, select your assembly and press "Update":
    18. Specify the location of the assembly to update:
    19. Finally click the button "Update Selected Plugins":



      And now you can debug again your plugin and see how the breakpoints are reached by the runtime.


      That's all...Enjoy Dynamics CRM


      כתב: כרמל שוורצמן

    Tuesday, November 19, 2013

    How to Extend the Dynamics CRM Entity Class to enable Indexing for Late Binding

    by Carmel Schvartzman

    1. In this walkthrough we will learn Step-By-Step  How to Extend the CRM2011 Entity class enabling Indexing while calling a Web Service in Dynamics CRM 2011. We'll call the CRM 2011 WCF Web Service and perform CRUD operations using Indexing on the generic Entity class.  We'll consume the CRM 2011 Organization (SOAP) services from a class which can also be used by a console application, or a Windows Service, or a Windows Form application.
      We'll not use the Microsoft CRM SDK designed for Early Binding; instead we'll reach directly the CRM 2011 WCF SOAP endpoint to perform the CRUD operations for Late Binding.
    2. By enabling Indexing we mean that we could access an Entity property getting/setting its value, by using an " entity["field_name"]  "  sintax, while reaching Crm2011 from a WIN app via its Organization Web Service. Therefore, a code like the following....:
      How to Extend the Dynamics CRM Entity Class to enable Indexing for Late Binding

      ... will allows us to create a new Contact, for example:
    3. In order to create a client for the CRM2011 Organization Service, we'll create a .dll which will send requests to the CRM2011 Organization Web Service Endpoint. Then, we'll create a WIN project to use that assembly and fetch the CRM data, and also create new entities.
    4. So let's create a new Class Project in Visual Studio 2010 or 2008, selecting the target framework to be version 3.5:
    5. Next, add the CRM 2011 Web Service reference to the project:
    6. Remember that we'll be using the Organization CRM Web Service, so type the address:
    7. After adding the Web Service, rename the Class :
    8. Code an static method returning an IOrganizationService object. This function will receive as parameters the host, organization and user logon data:
    9. Now add the following security code for reaching the CRM Web Service :





      SymmetricSecurityBindingElement security = new SymmetricSecurityBindingElement();
      security.ProtectionTokenParameters = new SspiSecurityTokenParameters();
      HttpTransportBindingElement httpTransport = new HttpTransportBindingElement();
      httpTransport.MaxReceivedMessageSize = Int32.MaxValue ;
      CustomBinding binding = new CustomBinding();
      binding.Elements.Add(security);
      TextMessageEncodingBindingElement encoding =
      new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressing10, Encoding.UTF8);
      binding.Elements.Add(encoding);
      binding.Elements.Add(httpTransport);

       
    10. Now add the WCF Endpoint code:



      EndpointAddress endpoint =
      new EndpointAddress(new Uri(string.Format("{0}/{1}/XRMServices/2011/Organization.svc", host, organization)),
      EndpointIdentity.CreateUpnIdentity(string.Format("{0}@{1}", user, "")), new AddressHeader[] { });

       
    11. And finally add the code to create the Client:





      OrganizationServiceClient client = new OrganizationServiceClient(binding, endpoint);
      client.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(user, password, "");

       
    12. Check that we have all the "usings" we need:
    13. Also, check whether all the references are listed:
    14. Now, in order to perform the testings on our class, create a new console Project , which will call our CRM assembly:
    15. Add the following references:
    16. First, add the Runtime.Serialization assembly:
    17. Second, add our class assembly:
    18. Now, code a call to the IOrganizationService:
    19. Add the corresponding using:
    20. ... and type the relevant logon data, for security reasons:
    21. Next, select some columns that you want to retrieve, and instantiate the entity object:
    22. Check in the QuickWatch window that you get an account with the required attributes:


    23. Now, try to use the  "account["field_name"]" sintax, that means to use Indexing on the Entity class:
    24. It seems that,  if we want to use the "account["field_name"]" sintax, we'll be confronted with an error:
    25. Same thing will happen if we try to create a new record, let's say a new Contact:
    26. According to the error message, Indexing cannot be applied to an Entity.
    27. To solve the problem, let's add Indexing support to the Entity class. We'll extend the Entity class by using two collections: the FormattedValueCollection and the RelatedEntityCollection:
    28. Loockup also the RelatedEntityCollection documentation on MSDN:
    29. Both collections are defined as OptionalFieldAttribute on the Serialization assembly, meaning that the formatters will not require such fields while serializing the Entity class:
    30. Take a look at the FormattedValuesField in the "References" .cs file on your project:


      As you can see, the Entity class is partial, can be extended, and the FormattedValuesField is an optional collection.
    31. Therefore, the first thing we'll do is instantiate those two fields in the partial Entity constructor:
    32. Next, we'll add the Indexing feature to allow a "entity["field_name"] " sintax:
    33. Then, code the get/set functions of the indexing using the AttributeCollection class:
    34. Press "F12" on the AttributeCollection to see that object:


      It's a generic List<> of  KeyValuePair<string,object>, therefore let's code according to that.
    35. Create a static class to hold the Extensions we need to interact with that List<>. Inside the static class, type the get - set extension methods for that List<>:
    36. There are two simple cases that can happen while getting-setting a value from-to a collection. Let's code against them first. In the case of the "get" extension method, prepare to throw an exception if the key does not exists:
    37. In the case of the "set" extension method, the value does not exists in the collection, so just add it to the List.
    38. Next, the two important cases are when the value is in the collection , and we need to know the index it is in, in order to fetch it....:


      ...and when the value is in the collection, and we must override it with the new value. In both cases we'll use a method to get the index of the cell holding the value: GetIndex<K,V>(IList<> col,K key, out i).
    39. Create the  GetIndex<K,V>(IList<> col,K key, out i) method:
    40. Code the basic case in which the collection is null:
    41. .. Next add the code for the Index search:
    42. We're done. Compile and run the WIN Startup Project which uses the assembly:

      We can see that the Indexing is now working, and we can fetch the Account name, and also create a new Contact record.
    43. Finally, let's check our CRM 2011 Workplace to see the new Contact added:




      That's all...Enjoy Dynamics CRM


      כתב: כרמל שוורצמן