Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

email casting issue in plugin?

$
0
0
Hello - I'm trying to get a handle to the email entity in the Email post-save plugin.

The following code *was* working at 1 point because the plugin was able to complete and save:

            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                // obtain the target entity from the input parameters
                var email = (Email)context.InputParameters["Target"];

However, now the last line is returning the following error:

"Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'MyGennedEntities.Email'"

I also tried using the following code in the last line:

var email = ((Entity)context.InputParameters["Target"]).ToEntity<Email>();

However, this code returns the following error at runtime:

"Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'MyGennedEntities.ActivityParty'"

Any idea what I'm doing wrong here, what might be going wrong, how to fix or debug?

Viewing all articles
Browse latest Browse all 8223

Trending Articles