Hi everyone,
I am working on a SP Online (PWA) addin and I am trying to create a task in a project with the following code:
public void AddTask( Guid projectUid ) { using ( ProjectContext projectContext = spAccessManager.CreateUserProjectContextForSPHost() ) { var pubProject = projectContext.Projects.GetByGuid( projectUid ); var currentUser = projectContext.Web.CurrentUser; projectContext.Load( pubProject ); projectContext.Load( currentUser ); projectContext.ExecuteQuery(); // Always checkin if ( pubProject.IsCheckedOut ) { // Assuming the project is checked out to the current user projectContext.WaitForQueue( pubProject.Draft.CheckIn( false ), int.MaxValue ); } // Load tasks var draftProject = pubProject.CheckOut(); projectContext.Load( draftProject ); projectContext.Load( draftProject.Tasks); projectContext.ExecuteQuery(); // Create new task var taskInfo = new TaskCreationInformation(); taskInfo.Id = Guid.NewGuid(); taskInfo.Name = "_" + DateTime.Now; taskInfo.IsManual = false; taskInfo.Duration = "1d"; draftProject.Tasks.Add( taskInfo ); var job = draftProject.Update(); // result is Success... var result = projectContext.WaitForQueue( job, int.MaxValue ); // but this throws an exception because there is an error from the queueu from last operation job = draftProject.Publish( false ); var result2 = projectContext.WaitForQueue( job, int.MaxValue ); } }
"spAccessManager" is a custom object generating the ProjectContext and it is using the default functionality in TokenHelper.cs and SharepointContext.cs from the VS template.
I use this code just as a proof of concept and I intentionally checkin and checkout every time. In theory it should work, but when the project is checked out in the browser - an error occurs after the Update operation (despite the fact that the result is Success):
- Project:
- ProjectSchedulingEngineException (9133). Details: id='9133'
name='ProjectSchedulingEngineException'
uid='7e0bcea7-30e1-e511-80c8-00155d58bd1e'
exception='System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Office.Project.Server.BusinessLayer.ProjectEngineUpdate.UpdateProjectWithPCS(IPlatformContext context, ProjectDataSet dataset, Guid projectUid, Guid sessionUid, Boolean inVisibilitySyncMode, Boolean skipEventHandlers, Boolean skipPostSSPUpdate) at Microsoft.Office.Project.Server.BusinessLayer.ProjectMain.HandleProject2(MessageContext mContext, ProjectDataSet dataset, Guid projectUid, Guid sessionUid, Boolean inVisibilitySyncMode)'
.
- ProjectSchedulingEngineException (9133). Details: id='9133'
- Queue:
- GeneralQueueJobFailed (26000) - ProjectUpdate.ProjectUpdate2Message. Details: id='26000'
name='GeneralQueueJobFailed'
uid='7f0bcea7-30e1-e511-80c8-00155d58bd1e'
....................
- GeneralQueueJobFailed (26000) - ProjectUpdate.ProjectUpdate2Message. Details: id='26000'
If I close the project in the browser (from the button in the ribbon) without checking it in, the code executes successfully. Also when I wait for about 20 minutes, the code is running again as expected.
This is a pretty simple operation, I did not expect such issues. Has anyone had similiar problem? Any ideas what might be causing this?