Unable to cast object of type ‘Microsoft.Crm.Sdk.Moniker’ to type ‘Microsoft.Crm.Sdk.DynamicEntity’
I was writing my first callout ( plugin) for CRM 4.0 when i recieved this error.
I realized that this was because of this line of code in my plugin
public void Execute(IPluginExecutionContext context)
{
DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties[“Target”];
……
For Create and Update message there was no problem.
Problem started coming when i registered the step for Assign message.
So modified the code as following
DynamicEntity entity = null;
if (context.InputParameters.Properties.Contains(“Target”) &&
context.InputParameters.Properties[“Target”] is DynamicEntity)
{
// Obtain the target business entity from the input parmameters.
entity = (DynamicEntity)context.InputParameters.Properties[“Target”];
}
For Assign Message used the following line of code
if (context.MessageName == “Assign”)
{
Moniker myMoniker = null;
if (context.InputParameters.Properties.Contains(“Target”) &&
context.InputParameters.Properties[“Target”] is Moniker)
{
// Obtain the target business entity from the input parmameters.
myMoniker = (Moniker)context.InputParameters.Properties[“Target”];
}
myMoniker.Name –> Gave the name of the entity
myMoniker.Id –> Gave the id of the entity
Bye
This was originally posted here.

Like
Report
*This post is locked for comments