Hi All,
I'm at my wits end with this issue and hence the post. I have a plugin that runs on the Update message for an entity. The plugin does some stuff and at the end sends an email. I have trace code throughout the plugin which shows that the code executes all the way down to this line below and then throws an error.
localContext.Trace("SendEmailResponse Object initialised.");
// The above line can be seen in the stack trace so its the line below that errors.
SendEmailResponse sendEmailResp = (SendEmailResponse)localContext.OrganizationService.Execute(sendEmailReq);
Stack Trace for the error is...
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Object reference not set to an instance of an object.Detail:
<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
<ErrorCode>-2147220891</ErrorCode>
<ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic">
<KeyValuePairOfstringanyType>
<d2p1:key>OperationStatus</d2p1:key>
<d2p1:value xmlns:d4p1="www.w3.org/.../XMLSchema" i:type="d4p1:string">0</d2p1:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<d2p1:key>SubErrorCode</d2p1:key>
<d2p1:value xmlns:d4p1="www.w3.org/.../XMLSchema" i:type="d4p1:string">-2146233088</d2p1:value>
</KeyValuePairOfstringanyType>
</ErrorDetails>
<Message>Object reference not set to an instance of an object.</Message>
<Timestamp>2017-11-23T12:57:27.2141815Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText>
[ePermits.Plugins: ePermits.Plugins.PostElectricalStandingInstructionUpdate]
[524be194-51a3-e711-80da-001dd8b71dde: PostElectricalStandingInstructionUpdate]
Entered ePermits.Plugins.PostElectricalStandingInstructionUpdate.Execute(), Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
ePermits.Plugins.PostElectricalStandingInstructionUpdate is firing for Entity: cal_electricalstandinginstruction, Message: Update, Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
Passed plugin registration checks., Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
AE and owner Id column value successfully retrieved., Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
Authorising Engineer is not null and is :Another User, Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
Access Granted, Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
AE GUID:e9ee81a8-16a4-e711-80da-001dd8b71dde, Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
Created activity parties., Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
Email Created., Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
ec70afda-4dd0-e711-80dc-001dd8b71dde, Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
SendEmailResponse Object initialised., Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
Exiting ePermits.Plugins.PostElectricalStandingInstructionUpdate.Execute(), Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
Now strangely enough if I select in Email To: a user that is Sys Admin, then this code runs without error but if I select a user who is not sys admin then it errors with the error above. So I'm confident that this error is related to security roles of the Email To user. However, without a clear error message I dont know which security role setting I need to change which will solve this problem. Any ideas?