Microsoft Dynamics CRM 2011

Microsoft Dynamics CRM 2011

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

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


Sunday, August 31, 2014

PlugIns - How to SAFELY COPY SOURCE VALUES TO TARGET FIELDS in a CRM 2013 C# Workflow

by Carmel Schvartzman
  1. This is the Building Block C# code to SAFELY COPY SOURCE VALUES TO TARGET FIELDS in a CRM 2013 C# Workflow. When using the late binding approach , you would probably be faced with web services errors related to types mismatch . Usually , you would need to waste much time looking for the specific field which caused the error . The goal of this tutorial is to avoid falling into that kind of problems when developing CRM plugins with the late binding approach . 
  2. The present code relates to a custom  Plugin / Workflow in Dynamics CRM 2011/2013. 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.
  3. After you set up the Xrm Organization Service that you need to interact with the CRM organization, you can use the following code to COPY values fetched through the CRM Web Service, which we call here "sourceEntity",  to your local "targetEntity" . We include here 4 scenarios : an INT field, STRING, DECIMAL & DATETIME : each one of them will be copied SAFELY, meaning that because we are using late binding here, we will avoid causing web service exceptions :

SAFELY COPY SOURCE VALUES TO TARGET FIELDS IN PLUGIN WORKFLOW

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  
///////////////////////  CASE #1 ) STRING :  ////////////////////////////////////////
if (sourceEntity.Attributes.ContainsKey("source_field"))               
     {                    
           targetEntity["target_field"] =  Convert.ToString(sourceEntity.Attributes["source_field"]);               
      }





//////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////  CASE #2 ) INT :
/////////////////////////////////

if (sourceEntity.Attributes.ContainsKey("source_field") )            
{                
   int iCode = 0;                
   if (Int32.TryParse(Convert.ToString(sourceEntity.Attributes["source_field"] ), out iCode))                
   {                   
       targetEntity.Attributes["target_field"] = iCode;                
   }            
}




//////////////////////////////////////////////////////////////////////////////////////////////////             
 /////////////////  CASE # 3 ) MONEY - DECIMAL : //////////////////////
if (sourceEntity.Attributes.ContainsKey("source_field") )            
{                
   decimal mValue = 0.0M;               
    if ( Decimal.TryParse(Convert.ToString(sourceEntity.Attributes["source_field"] ), out mValue ))               
    {                    
         targetEntity.Attributes["target_field"] = mValue;                
     }            
}




//////////////////////////////////////////////////////////////////////////////////////////////////                      
//////////  CASE #4 ) DATETIME : /////////////////////////////////
if (sourceEntity.Attributes.ContainsKey("source_field") )           
{               
         decimal mValue = 0.0M;               
         if ( Decimal.TryParse(Convert.ToString(sourceEntity.Attributes["source_field"]), out mValue ))               
       {                   
            targetEntity.Attributes["target_field"] = Convert.ToDateTime( sourceEntity.Attributes["source_field"]);               
        }           
}


////////////////////////////////////////////////////////////////////////////////////////////////





The present article is about how to SAFELY COPY SOURCE VALUES TO TARGET FIELDS in a CRM 2013 C# Workflow.
That's all...Enjoy Dynamics CRM 2013!!!


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