RunTask throws error message

Hi all,

I am writing an application that searches a vault and then converts certain files into STEP . There is already a defined task for this STEP conversion. When I try to start the task automatically with the RunTask method, I always get the error message “The supplied object id is not valid”.
I’ve copied the procedure from the pdm api example " Get and Run a Task Add-in Example (C#)".
PDM-Version is 2023
_filesToStep is a List

private static void RunTask()
	EdmSelItem2[] selection = new EdmSelItem2[ _filesToStep.Count ];

	for( int i = 0; i < _filesToStep.Count; i++ )

		IEdmFile17 file =(IEdmFile17) _vault.GetFileFromPath( _filesToStep[i].Path, out IEdmFolder5 folder );

		selection[ i ].mlID = file.ID;
		selection[ i ].mlParentID = folder.ID;
		selection[ i ].mlVersion = file.CurrentVersion;
		selection[ i ].meType = EdmObjectType.EdmObject_File;

		IEdmTaskMgr taskMgr = (IEdmTaskMgr)_vault.CreateUtility( EdmUtility.EdmUtil_TaskMgr );
		Array tasks = taskMgr.GetTasks();

		string cleanedInput = _taskName.Trim().Trim( '"' );

		EdmTaskInfo stepTask = tasks.OfType<EdmTaskInfo>().FirstOrDefault(
		task => string.Equals( task.mbsTaskName, cleanedInput, StringComparison.OrdinalIgnoreCase ) );

		taskMgr.RunTask( stepTask, selection, 0 );
	catch( Exception ex )
		_logger.Error("The Task cannot be executed. --> " +  ex.Message );

Does anyone has an idea?

Just a couple of things to start.

  1. Do your interop files have “Embed Interop Types” set to “False”? If not, set to false and try again.
  2. In your project properties, assuming visual studio, is “Prefer 32-bit” un-checked? If not, un-check and try again.
1 Like

Thanks Al,
the 2. point was the issue. Unchecked and it worked properly.
Thanks a lot!