Hello,
1. I know this question shows up a lot and has been answered quite often. I've looked through the reponses and so far none of them have helped.
2. I am relatively new to developing plugins for dataverse, so parden any "newbie" silly errors.
I'm attempting to update an entity based on a calculated date. When running the plugin in dataverse without profiling I'm getting the error "Object reference not set to an instance of an object." When I try and debug this error using the profiler I get an error that simply states to download the error file. When attempting to profile using 'Persist to Entity' option I'm getting an "Unable to persist the profile." error message and the profile doesn't save for debugging.
"
Exception Message: Object reference not set to an instance of an object.
ErrorCode: -2147220956
HexErrorCode: 0x80040224
HelpLink: go.microsoft.com/.../
TraceText:
[CreateProgramStartSchedule: CreateProgramStartSchedule.CreateProgramSched
[fd550148-3572-ed11-9561-00224805caa9: CreateProgramStartSchedule.CreateProgramSched: Update of pt_programstarts
Activity Id: 7e06306d-995a-4954-96d5-83c6acfe707a
"

I know this error usually indicates that one of the values I'm trying to update is null, but this doesn't seem to be the case.
In the code below the error is occuring on "service.Update(ProgramStart);" regardless of which version of the code I run.
The code that is commented out is different variations that I've tried.
if (WorkingHours >= (SessionNumber * SessionHours))
{
SessionEnd = WorkingDate;
if (SessionNumber == 1)
{
// save value as end of first session of this start
/*
NextStartFlag = true;
object[] EndDateField = {"pt_enddate", WorkingDate };
UpdateEntity("pt_programstarts", ProgramStart.Id, EndDateField, service);
*/
/*
Entity UpdateProgramStart = new Entity("pt_programstarts", ProgramStart.Id);
UpdateProgramStart.Attributes.Add("pt_enddate", WorkingDate);
service.Update(UpdateProgramStart);
*/
ProgramStart.Attributes.Add("pt_enddate", WorkingDate);
service.Update(ProgramStart);
}
"pt_programstarts" is the correct logical name for the entity.

"pt_enddate" is the correct name for the field.

The Variable "WorkingDate" does have a value.

The entity "pt_programstarts" has a valid Guid and seems to be a valid entity.

Just for complete information..

private void UpdateEntity(string EntityName, Guid EntityGuid, object[] Field, IOrganizationService service)
{
Entity UpdateEntity = new Entity(EntityName, EntityGuid);
for(var i = 0; i < Field.Length; i )
{
string FieldName = Convert.ToString(Field[i]);
i ;
object FieldValue = Field[i];
UpdateEntity.Attributes.Add(FieldName, FieldValue);
}
service.Update(UpdateEntity);
}
Any ideas what I'm missing or what object isn't set?