web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Nishant Rana’s Weblog / Unable to cast object of ty...

Unable to cast object of type ‘Microsoft.Crm.Sdk.Moniker’ to type ‘Microsoft.Crm.Sdk.DynamicEntity’

Nishant Rana Profile Picture Nishant Rana 11,325 Microsoft Employee

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.

Comments

*This post is locked for comments