Ask a questionAsk a question
 

Proposed AnswerOnTaskChange is not running

  • Wednesday, April 11, 2007 9:15 AMSteve4042322 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    I have created a sequential workflow in Visual Studio 2005, and the tasks are created inside the workflow (CreateTask), and then updated from a custom ASPX form. The problem is that the OnTaskChanged event does not execute when the task is updated.This was working OK, but now it does not fire. The Task is definitely updated, since I change the status and add comments. Further, I also found that if I change the task inside SharePoint UI, then the OnTaskChange code is run.

     

    I did check the Logs, and found the following error message. Is it possible that the SharePoint server and Workflow engine are out of synch? I have restarted the server, but still the problem remains.

     

    I would appreciate any suggestions to resolve this.

     

     

    04/11/2007 11:45:55.24  w3wp.exe (0x17DC)   x1590 Windows SharePoint Services    General

     

    ERROR: request not found in the TrackedRequests. We might be creating and closing webs on different threads.
    ThreadId = 6, Free call stack =    at Microsoft.SharePoint.SPRequestManager.Release(SPRequest request)     at Microsoft.SharePoint.SPSite.Close()    
    at Microsoft.SharePoint.SPSite.Dispose()    
    at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.AutoStartWorkflow(SPItemEventProperties properties, Boolean bCreate, Boolean bChange, AssocType atyp)    
    at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.AutoStartWorkflow(SPItemEventProperties properties, Boolean bCreate, Boolean bChange)    
    at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.ItemAdded(SPItemEventProperties properties)    
    at Microsoft.SharePoint.SPEventManager.RunItemEventReceiver(SPItemEventReceiver receiver, SPItemEventProperties properties, SPEventContext context, String receiverData)   
     at Microsoft.SharePoint.SPEventManager.RunItemEventReceiverHelper(Object receiver, Object properties, SPEventContext context, String receiverData)    
    at Microsoft.SharePoint.SPEventManager.<>c__DisplayClass8`1.<InvokeEventReceivers>b__0()    
    at Microsoft.SharePoint.SPSecurity.CodeToRunElevatedWrapper(Object state)    
    at Microsoft.SharePoint.SPSecurity.RunAsUser(SPUserToken userToken, Boolean bResetContext, WaitCallback code, Object param)    
    at Microsoft.SharePoint.SPSecurity.RunAsUser(SPUserToken userToken, CodeToRunElevated code)    
    at Microsoft.SharePoint.SPEventManager.InvokeEventReceivers[ReceiverType](SPUserToken userToken, RunEventReceiver runEventReceiver, Object receivers, Object properties, Boolean checkCancel)    
    at Microsoft.SharePoint.SPEventManager.InvokeEventReceivers[ReceiverType](Byte[] userTokenBytes, RunEventReceiver runEventReceiver, Object receivers, Object properties, Boolean checkCancel)    
    at Microsoft.SharePoint.SPEventManager.HandleEventCallback[ReceiverType,PropertiesType](Object callbackData)   
    at Microsoft.SharePoint.Utilities.SPThreadPool.WaitCallbackWrapper(Object state)    
    at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)    
    at System.Threading.ExecutionContext.runTryCode(Object userData)
    at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)  , Allocation call stack (if present) null 

All Replies

  • Wednesday, April 11, 2007 2:13 PMSimon Doy Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Steve,

    Just a thought has the CreateTask and OnTaskChange activity got the same colleration token specified for the task?

     

    Regards

    Simon

  • Wednesday, April 11, 2007 2:33 PMSteve4042322 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Simon,

     

    Yes. They share the same token, and I checked they are at the same scope. But you are correct, this is the connection between the task and onchange handler. I will create a more simple workflow to determine if the problem is inside my WF, or an external factor. I will let you know the result.

  • Wednesday, April 11, 2007 3:15 PMSimon Doy Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Steve,

    I have seen this before with one of my workflows but I also had a problem with my development environment. After I updated my environment the problem disappeared. Not that I think they are related - but thought I'd mention just in case.

     

    Simon

     

     

  • Thursday, May 03, 2007 9:17 AMherve.delannoy Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello
    I have the same problem...

    I tried to build my own workflow with aspx initiation and association forms. My workflow is just composed by an activity : a createTask Activity. Association form works fine, but i never see the instanciation form... And the create task activity makes an error. See below the code and the logs.

    Could anyone help me? thanks a lot for any answer !

    Code Snippet

    workflow.xml :
    ...
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Workflow
    Title="Demo Sample"
    Name="WF Sample"
    Description="Demo Sample Description."
    Id="A475....525763"
    CodeBesideClass="WF_Test.Workflow1"
    CodeBesideAssembly="WF_Test, Version=3.0.0.0, Culture=neutral, PublicKeyToken=d2e8f...66bdb1"
    AssociationUrl="../_layouts/work/assoc_form.aspx"
    InstantiationUrl="../_layouts/work/inst_form.aspx"
    >
    <Categories/>
    </Workflow>
    </Elements>




    Logs :

    Code Snippet

    System.InvalidOperationException: Correlation value on declaration "workflowToken" is already initialized.
    ERROR: request not found in the TrackedRequests. We might be creating and closing webs on different threads.


    Element of answer are here :
    http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=1553658&SiteID=17&mode=1
  • Monday, May 14, 2007 1:15 PMPraveenBattula Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    make sure that workflow correlation token and create task correlation token are different

    for create task,  correlation token needs to be created, but not workflowToken

    thanks
    praveen
  • Monday, May 14, 2007 1:45 PMCDam Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hello,

     

    I've got the same problem than Steve....

     

    It's not a correlation token problem because my workflow works well when I made my tasks modifications using Sharepoint UI!

     

    However, as soon as I'm trying to update my task using specific code outside "Workflow code", the event OnTaskChanged is not fired....

     

    Many thanks for your help!

  • Monday, May 14, 2007 10:39 PMRodrigo Díaz ConchaMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I had the same issue but I've resolved it using the SPWorkflowTask.AlterTask() method  and not the SPWorkflowTask.Update() itself.

     

    Hope this help!

  • Tuesday, May 15, 2007 7:06 AMCDam Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hello,

     

    Unfortunately, I've already tried to use SPWorkflowTask.AlterTask() instead of Update() method....

    and it hasn't worked....

     

    Looking for others solutions...

     

    Thanks

  • Thursday, May 17, 2007 4:14 PMKevinHou Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I'm also getting this error.  However, my workflow is even simpler than those described here.  My workflow has a createTask activity and a Code activity, and a logToHistoryListActivity activity.  The workflow compeletes successfully but this error is still in the log files.  Anyone know why?

     

    Thanks,
    Kevin

  • Friday, May 18, 2007 4:44 AMPraveenBattula Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    make sure that in your designer.cs class workflow token defined twice or initialized twice.

    thanks
    praveen
  • Friday, May 18, 2007 1:59 PMKevinHou Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Praveen,

     

    Thanks for helping me.  I looked in my designer.cs file and found only one reference to my workflow token:

     

    correlationtoken2.Name = "workflowToken";

     

    How or where do I define it a second time as you suggest.  Also, this is designer generated code, if it needs to be in there twice, shouldn't the designer do it for me?

     

    Kevin

  • Friday, May 18, 2007 6:56 PMMaycon Carrazedo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    Hi,

     

    I´m having this problem with a State Machine Workflow, the token is the same to the Create Task and OnTaskChanged actions, but the workflow just finish without erros in the WSS, instead of wait the task change.

     

    // Code that create the Token and assing in the CreateTask action

    correlationtoken4.Name = "AnaliseJuridicoToken";

    correlationtoken4.OwnerActivityName = "stateAnaliseJuridico";

    this.createTaskWithContentType1.CorrelationToken = correlationtoken4;

     

    // Code that assing the Token tho the OnTaskChanged

    this.onTaskAJChanged.CorrelationToken = correlationtoken4;

     

    Even if I change the Initial State to another one, the problem persist.

     

    Any idea?

     

    Tank´s.

  • Monday, September 24, 2007 2:42 PMRoDo777 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I had the same problem.

     

    And my mistake was, to create different correlationTokes for the task.

     

    I've done this because i choose the wrong OwnerActivityName at OnTaskChanged.

    ( i choose ActEvtDrivenOnTask01Changed instead of the top WF activity WF02)

    When I wanted to compile i got "The correlation token for Activity createTask01 has an

    owner activity name which is not its parent".

    So I created another one.

     

    If you choose the name of the WF itself in OwnerActivityName for both then everything is fine again

    :-)

     

  • Friday, April 25, 2008 9:00 PMSomak Bhattacharyya Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    For all those people who are facing this issue, can you please check the following two things in your code:

    1. The Correlation Tokens are fine, i.e.; the same token passes through "Create Task" --> "On Task Created" --> "On Task Changed" --> "On Task Completed".
    2. If the above is fine, do check the method that is getting invoked by each of these activities. For example,
      "Create Task" should invoke the CreateTask_MethodInvoking(or your custom function name) and "On Task Changed" should OnTaskChanged_MethodInvoking(or your custom method name) so on and so forth. Try to find out if all these activities are mapped one to one to their functions and there is no cross connections like "OnTaskChanged" invokes the function that is being called by "OnTaskCreated" etc.
    3. If you have created a new Correlation Token for your task, make sure that you are calling your own Correlation Token. Also make sure that the "OwnerActivityName" should always be your workflow name. In case you have renamed your Workflow from the default "Workflow1" then make sure that the custom name is in place for all the Correlation Tokens!
    4. Also check that all your activities point to the same Task ID. That is should point to the Task ID you have given to your "Create Task" activity. I would suggest you to visit the following sites:
      http://weblog.vb-tech.com/nick/archive/2007/02/25/2207.aspx
      http://weblog.vb-tech.com/nick/archive/2007/03/05/2241.aspx
      for a really great Walkthrough. Or alternatively you may want to visit http://www.sheltonblog.com/ for a real wealth of resources and Video. Just search for it inside the site and you'll find tremendous amount of information.

    Doing the above steps should solve your problem if it is not any environmental issue!

  • Friday, June 27, 2008 7:23 PMmattdanna Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    Somak,

     

    In 3. you said to make sure the OwnerActivityName was the name of the Workflow.  Would this still be the case if your onTaskChanged eventwas inside a SequentialActivity.  Would the SequentialActivity name be the OwnerActivityName?  I am having the same problem but only periodically.  It seems like it's losing the event handler somehow and I need to fix it asap.

     

    Thanks in advance,

    Matt

  • Wednesday, July 02, 2008 12:58 PMSomak Bhattacharyya Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hey Matt,

     

    Sorry for the late reply. Since your Workflow is failing only intermittently, and is working as expected otherwise, I don't think there is a problem with your Correlation Tokens, OwnerActivityName, TaskID etc.. Are you being able to reproduce the issue? Is it occurring only in some special cases? Or is the behaviour random? If you send me your code and the SharePoint Log files (under 12\logs) containing the error text, I can look through it. And may be in best case we can track the error.

     

    You can mail me at somak.bhattacharyya@live.com.

     

    Thanks and Regards,

    Somak.

  • Thursday, August 14, 2008 8:09 AMCiBiaR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code

    Hello,

    I've been following this thread since the beginning because I'm exeperiencing same problems as Steve, herve.delannoy, CDam and others.

    I have created a sequential workflow in Visual Studio 2008 to use it on a MOSS server to manage documents added to a Document library. A variable number of tasks are created inside the workflow thru a Replicator activity in the way shown in the following outline:

        OnWorkflowActivated
        (...)
        1.1  SequenceActivity
        1.1.1  Replicator
        1.1.1.1  Sequence
        1.1.1.1.1  CreateTaskWithContentType
        1.1.1.1.2  While
        1.1.1.1.2.1      Sequence
        1.1.1.1.2.1.1        OnTaskChanged
        1.1.1.1.2.1.2        If(Condition)
        1.1.1.1.2.1.2.1           UpdateTask
        1.1.1.1.3  CompleteTask
        1.1.1.1.4  LogToHistoryListActivity

    Tasks are updated from a custom ASPX form thru SPWorkflowTask.AlterTask method with a code block like this being executed when user clicks Approve button:

        SPSite lGlobalSite = SPControl.GetContextSite(Context);
        SPWeb lSite = lGlobalSite.OpenWeb();
        string lParamSPListGuid = Request.Params["List"];
        string lParamTaskListItemID = Request.Params["ID"];

        SPListItem lTaskListItem = lSite.Lists[new Guid(lParamSPListGuid)].GetItemById(System.Convert.ToInt16(lParamTaskListItemID));
        SPList lTaskListAttachedTo = lSite.Lists[new Guid(lParamSPListGuid)];
        Guid lWorkflowInstanceGuid = new Guid(Convert.ToString(lTaskListItem["WorkflowInstanceID"]));

        Hashtable lTaskHash = new Hashtable();
        lTaskHash["_ApprovalNotes"] = txtApprovalNotes.Text;
        lTaskHash["_ApprovalStatus"] = aApprove;

        lSite.Dispose();

        SPWorkflowTask.AlterTask(lTaskListItem, lTaskHash, false);

        SPUtility.Redirect(lTaskListAttachedTo.DefaultViewUrl, SPRedirectFlags.UseSource, HttpContext.Current);


    Once  the button is clicked, task should be updated and the workflow awakened with a OnTaskChanged event where custom code updates Document Library’s custom column values, as shown bellow:

        NumTasksCompleted++;

        Guid statusFieldID = workflowProperties.TaskList.Items[0].Fields["Approval Form Status Field"].Id;
        this._taskApprovalStatus = System.Convert.ToBoolean(onTaskChanged2_AfterProperties1.ExtendedProperties[statusFieldID]);

        if (this._taskApprovalStatus)
        {
           NumTasksApproved++;
        }

        Guid notesFieldID = workflowProperties.TaskList.Items[0].Fields["Approval Form Notes Field"].Id;

        if (onTaskChanged2_AfterProperties1.ExtendedProperties[notesFieldID] != null)
        {
            _approverNotes = onTaskChanged2_AfterProperties1.ExtendedProperties[notesFieldID].ToString();
        }

        this._taskCompleted = true;


    The problem is that although task's notes and status are always updated, OnTaskChanged event does not always execute in my workflow after user clicks Approve button.

    The problem does not happen after a given number of workflows executed/completed or a given number of tasks created/assigned. Workflow can work flawlessly more than 10 times, creating and assigning about 60 tasks in total and allowing me to complete them all. But maybe next time I start it, everything stops working after clicking Approve button on the ASPX form that approves a task. Even worse, it happens more often in the actual server where workflow is installed than in the almost identical virtual machine used as test environment.

    When this happens, Redirect method send the browser back to Task list where the task shows 'Not Started' under Status column, and document library shows 'In progress' status for my workflow. Sometime, after waiting several minutes and/or restarting IIS, some of that tasks get completed, but most of them don't, and trying to re-approve them results in a 'This task is currently locked by a running workflow' exception.

    I've been looking for a solution to this behavior for weeks, and tried almost every suggestion I've found to date –including Somak Bhattacharyya's as of April 25-, but nothing seems to fix it.

    Lately, after making some changes in the workflow and keeping an eye on SharePoint log files and system Event viewer, I've noticed the following exception being thrown some minutes after workflow stops working

        "Error loading and running event receiver Microsoft.SharePoint.Workflow.SPWinOEItemEventReceiver
         in Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c.
        Additional information is below.

        : Thread was being aborted."


    And the corresponding log file content

    AppDomainUnloadListener.Stop(False) called. ShutdownReason=HostingEnvironment, this=15368010
    AppDomainUnloadListener.Stop() entered lock(this=15368010)
    AppDomainUnloadListener.Stop() about to AcquireWriterLock(), this.countdownSeconds=120
    AppDomainUnloadListener.Stop() finally{} block with (timedOut == false), ensured that all LRO thread finished
    Unregistered hosting environment for ID CMSCACHE1764382194
    AppDomainUnloadListener.Stop(False) called. ShutdownReason=HostingEnvironment, this=15368010
    AppDomainUnloadListener.Stop() entered lock(this=15368010)
    AppDomainUnloadListener.Stop() about to AcquireWriterLock(), this.countdownSeconds=120
    AppDomainUnloadListener.Stop() finally{} block with (timedOut == false), ensured that all LRO thread finished
    Unregistered hosting environment for ID CMSCACHE1521652287
    Unregistered hosting environment for ID CMSCACHE233053084
    AppDomainUnloadListener.Stop(False) called. ShutdownReason=HostingEnvironment, this=23011038
    AppDomainUnloadListener.Stop() entered lock(this=23011038)
    AppDomainUnloadListener.Stop() about to AcquireWriterLock(), this.countdownSeconds=120
    AppDomainUnloadListener.Stop() finally{} block with (timedOut == false), ensured that all LRO thread finished
    Entering MRU trim routine.
    Initial table size: 89040640 in 383 entries
    Final table size: 89040640 in 383 entries
    Exiting MRU trim routine.
    Initial table size: 89040640 in 383 entries
    Final table size: 89040640 in 383 entries
    Exiting MRU trim routine.
    RunWorkflow: System.Threading.ThreadAbortException: Thread was being aborted.     at System.Threading.WaitHandle.WaitOneNative(SafeWaitHandle waitHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)     at System.Threading.WaitHandle.WaitOne(Int64 timeout, Boolean exitContext)     at System.Threading.WaitHandle.WaitOne(TimeSpan timeout, Boolean exitContext) at Microsoft.SharePoint.Workflow.SPWorkflowInstanceBase.WaitUntilInstanceIdle(TimeSpan timeout) at Microsoft.SharePoint.Workflow.SPWorkflowHostServiceBase.WaitUntilInstanceIdle(SPWorkflowInstance workflow, TimeSpan timeOut)     at Microsoft.SharePoint.Workflow.SPWinOeEngine.RunWorkflow(Guid trackingId, SPWorkflowHostService host, SPWorkflow workflow, Collection`1 events, TimeSpan timeOut)     at Microsoft.SharePoint.Workflow.SPWorkflowManager.RunWorkflowElev(SPWorkflow originalWorkflow, SPWorkflow workflow, Collection`1 events, SPRunWorkflowOptions runOptions)
    System.Threading.ThreadAbortException: Thread was being aborted.     at Microsoft.SharePoint.Workflow.SPWorkflowManager.RunWorkflowElev(SPWorkflow originalWorkflow, SPWorkflow workflow, Collection`1 events, SPRunWorkflowOptions runOptions)
    Now terminating ULS (w3wp.exe, Microsoft.Office.Server.Native.dll)
    Now terminating ULS (w3wp.exe, onetnative.dll)
    Error loading and running event receiver Microsoft.SharePoint.Workflow.SPWinOEItemEventReceiver in Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c. Additional information is below.  : Thread was being aborted.
    Now terminating ULS (w3wp.exe, Microsoft.Office.Server.Native.dll)
    Now terminating ULS (w3wp.exe, onetnative.dll)


    Once the exception happens, workflow status in document library is 'Error occurred' and I’m not able to get any other new instance of my workflow to work as expected. However, other workflows already installed in the server –but in other document libraries- work without any problem.

    By the way, I have a version of my workflow and a set of log files ready to send to anyone willing to have a look at them. As I’ve run almost out of ideas, any help will be greatly appreciated.


    Thanks in advance

    Ramon

    • Edited byCiBiaR Thursday, August 14, 2008 8:44 AMCheck spelling
    •  
  • Tuesday, August 26, 2008 8:58 PMNoWirez Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed AnswerHas Code
    I thought I would add myself to the list here. My problem seems nearly identical to CiBiaR, except I am not even using a custom task form. The problem DOES seem random (between builds) and an additional detail I have not seen posted here would be the following:

    1. Workflow starts and creates task
    2. If the problem task is edited, the changes made in the UI show up in sharepoint just fine; however, the task is now locked by sharepoint and nothing after OnTaskCreated (including the OnTaskCreated_Invoked method) will fire.
    3. At this point, the entire workflow seems to become disconnected from sharepoint meaning: if any other tasks were created in parallel, editing them now results in the same total unresponsiveness / locking (even if the normally work just fine when completed ahead of the problem task).

    I HAVE gone through my designer.cs code and verified that the task token is not being recreated or duplicated.

    Example:
    ------

    this.OnTaskCreated_CreateADAccount.CorrelationToken = correlationtoken20;   
    this.OnTaskCreated_CreateADAccount.Executor = null;   
    this.OnTaskCreated_CreateADAccount.Name = "OnTaskCreated_CreateADAccount";  
     


    ------

    correlationtoken20 is used for OnTaskCreated, OnTaskChanged, etc...

    An excerpt from my ULS log:
    Engine RunWorkflow: System.Workflow.Activities.EventDeliveryFailedException: Event "OnTaskCreated" on interface type "Microsoft.SharePoint.Workflow.ITaskService" for instance id "6074c83e-d0ce-4de7-add4-2abf84f0a5ad" cannot be delivered. ---> System.NullReferenceException: Object reference not set to an instance of an object.     at Microsoft.SharePoint.Workflow.SPWorkflowHostServiceBase.LoadInstanceData(Guid instanceId, Boolean& compressedData)     at Microsoft.SharePoint.Workflow.SPWinOePersistenceService.LoadWorkflowInstanceState(Guid instanceId)     at System.Workflow.Runtime.WorkflowRuntime.InitializeExecutor(Guid instanceId, CreationContext context, WorkflowExecutor executor, WorkflowInstance workflowInstance)     at System.Workflow.Runtime.WorkflowRuntime.Load(Guid key, CreationContext context, WorkflowInstance workflowInstance)     at System.Workflow.Runtime.WorkflowRuntime.GetWorkflow(Guid instanceId)     at System.Workflow.Activities.WorkflowMessageEventHandler.EventHandler(Object sender, ExternalDataEventArgs eventArgs)     --- End of inner exception stack trace ---     at System.Workflow.Activities.WorkflowMessageEventHandler.EventHandler(Object sender, ExternalDataEventArgs eventArgs)     at Microsoft.SharePoint.Workflow.SPWinOETaskService.RaiseEvent(SPWinOeWorkflow workflow, SPWorkflowEvent workflowEvent, Object workItem, IPendingWork workHandler)     at Microsoft.SharePoint.Workflow.SPWinOeHostServices.Send(SPWinOeWorkflow winoeworkflow, SPWorkflowEvent e)     at Microsoft.SharePoint.Workflow.SPWinOeEngine.RunWorkflow(Guid trackingId, SPWorkflowHostService host, SPWorkflow workflow, Collection`1 events, TimeSpan timeOut)

    • Proposed As Answer byJeets Thursday, September 03, 2009 11:29 PM
    •  
  • Monday, October 06, 2008 12:36 PMmfalth Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    We had the same problem for weeks, and then we implemented the following advice from Somak Bhattacharyya (Microsoft) that did our day!

    Cross-verify that all the ID like TaskIDs etc. (GUIDs) that you are using in your Workflow code are generated runtime (e.g.; by using Guid.NewGuid() in C#) and are not set (hard-coded) in the code during development. 

    We have been able to finish off the delivery but are now left wondering how it can be that the lack of dynamic task IDs results in random problems that only show up in some environments whereas other environments run just fine. This makes troubleshooting very hard and suggests an environment problem at first glance. When you know what the problem is it all feels logical but when faced with a mysterious, random problem it is not that evident.

    Good luck to all you others who are fighting with this one!

    /Magnus
  • Friday, October 24, 2008 9:53 PMmj14 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
      I am having the same problem.

    It is a very very simple sequential workflow - cannot get simpler than this. Still, OnTaskChange event is not getting fired.
    I can even send the project file for the workflow, if someone is willing to review it. But there is not option for attachment.

    Its very basic workflow with  CreateTask -> OnTaskCreate ->CompleteTask . That is it. 

    I have
    1. Separate Correlation token for workflow and activity
    2. CreateTask, OnTaskCreate, CompleteTask have same correlation token and share same taskId.

    Here is the code below.

    namespace PermWorkFlow

    {
    public sealed partial class Workflow1: SharePointSequentialWorkflowActivity
    {

    public Workflow1()
    {
    InitializeComponent();
    }

    public Guid workflowId = default(System.Guid);
    public Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties workflowProperties = new Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties();
    public Guid taskId = default(System.Guid);

    private void onTaskCreated1_Invoked(object sender, ExternalDataEventArgs e)

    {
    SetTaskItemContributor(workflowProperties.TaskList, (e as SPTaskServiceEventArgs).afterProperties);
    }

    private void SetTaskItemContributor(SPList taskList, SPWorkflowTaskProperties taskProps)
    {

    SPListItem listItem = taskList.Items.GetItemById(taskProps.TaskItemId);
    SPRoleDefinition roleDefinition = listItem.Web.RoleDefinitions.GetByType(SPRoleType.Contributor);
    SPGroup group = listItem.Web.Groups[@"Something\players"];

    SPRoleAssignment roleAssignment = new SPRoleAssignment(group);
    roleAssignment.RoleDefinitionBindings.Add(roleDefinition);

    if (!listItem.HasUniqueRoleAssignments)
    {
    listItem.BreakRoleInheritance(false);
    }

    listItem.RoleAssignments.Add(roleAssignment);
    listItem.Update();
    }

    private void createTask1_MethodInvoking(object sender, EventArgs e)
    {
    taskId = Guid.NewGuid();
    }

    }

    }

    Please let me if anyone willing to review the workflow project.

  • Wednesday, April 29, 2009 12:36 AMkuke Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    My code uploads multiple files which kicks off an auto-start workflow on each item and sometimes one will randomly fail. I followed Somak's advice above and didn't get find anything wrong. (The Workflow is a State Machine and one of the first steps is to create a task).

    I initially thought it only happened when I was debugging, however further investigation reveals that this error does indeed occur randomly.

    I note that in the workflow code (I didn't write it), it initialises the Task ID (GUID) in the "onWorkflowActivated_MethodInvoking" method, so I'm wondering if this could be the cause. I usually initialise a Task's GUID in the "createTask_MethodInvoking" method.

    Current thoughts:
    • Change when the Task GUID gets set 
    • ... if that fails:
    • Manually start workflow for each item after upload process
    • Wait 1 second between uploads
    • Write another Timer Job which monitors if workflows succeed and if not, terminate and manually restart
    Any advice appreciated.
    ----------
    Here's the error:

    04/28/2009 19:19:19.14 w3wp.exe (0x1098)                                0x0F24 Windows SharePoint Services   General                                   0          Unexpected      ERROR: request not found in the TrackedRequests. We might be creating and closing webs on different threads. ThreadId = 12, Free call stack =    at Microsoft.SharePoint.SPRequestManager.Release(SPRequest request)     at Microsoft.SharePoint.SPSite.Close()     at Microsoft.SharePoint.SPSite.Dispose()     at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.AutoStartWorkflow(SPItemEventProperties properties, Boolean bCreate, Boolean bChange, AssocType atyp)     at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.AutoStartWorkflow(SPItemEventProperties properties, Boolean bCreate, Boolean bChange)     at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.ItemAdded(SPItemEventProperties properties)     at Microsoft.SharePoint.SPEventManager.RunItemEventRe...        

    04/28/2009 19:19:19.14* w3wp.exe (0x1098)                                0x0F24 Windows SharePoint Services   General                                   0          Unexpected      ...ceiver(SPItemEventReceiver receiver, SPItemEventProperties properties, SPEventContext context, String receiverData)     at Microsoft.SharePoint.SPEventManager.RunItemEventReceiverHelper(Object receiver, Object properties, SPEventContext context, String receiverData)     at Microsoft.SharePoint.SPEventManager.<>c__DisplayClass8`1.<InvokeEventReceivers>b__0()     at Microsoft.SharePoint.SPSecurity.CodeToRunElevatedWrapper(Object state)     at Microsoft.SharePoint.SPSecurity.RunAsUser(SPUserToken userToken, Boolean bResetContext, WaitCallback code, Object param)     at Microsoft.SharePoint.SPSecurity.RunAsUser(SPUserToken userToken, CodeToRunElevated code)     at Microsoft.SharePoint.SPEventManager.InvokeEventReceivers[ReceiverType](SPUserToken userToken, RunEventReceiver runEventReceiver, Ob...

    04/28/2009 19:19:19.14* w3wp.exe (0x1098)                                0x0F24 Windows SharePoint Services   General                                   0          Unexpected      ...ject receivers, Object properties, Boolean checkCancel)     at Microsoft.SharePoint.SPEventManager.InvokeEventReceivers[ReceiverType](Byte[] userTokenBytes, RunEventReceiver runEventReceiver, Object receivers, Object properties, Boolean checkCancel)     at Microsoft.SharePoint.SPEventManager.HandleEventCallback[ReceiverType,PropertiesType](Object callbackData)     at Microsoft.SharePoint.Utilities.SPThreadPool.WaitCallbackWrapper(Object state)     at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)     at System.Threading.ExecutionContext.runTryCode(Object userData)     at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)     at System.Threading.ExecutionContext.RunInternal(Exec...     

    04/28/2009 19:19:19.14* w3wp.exe (0x1098)                                0x0F24 Windows SharePoint Services   General                                   0          Unexpected      ...utionContext executionContext, ContextCallback callback, Object state)     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)     at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)     at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)  , Allocation call stack (if present) null    

    • Edited bykuke Wednesday, April 29, 2009 7:25 AMFurther Information
    • Edited bykuke Wednesday, April 29, 2009 7:25 AM
    •  
  • Wednesday, May 13, 2009 4:57 PMSomak Bhattacharyya Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer
    Here's a comprehensive list of all the things that you may want to verify whenever you face some unwanted and mystic issues with SharePoint Workflows.

    I’ll give some random suggestions (Please understand that I am firing blankly here because I am not very sure of the issue that you are facing, i.e.; the failure point). These are arranged in decreasing order of probability:

    1.       Cross-verify that all the ID like TaskIDs etc. (GUIDs) that you are using in your Workflow code are generated runtime (e.g.; by using Guid.NewGuid() in C#) and are not set (hard-coded) in the code during development.

    2.       You are not having any concurrency/lock issues because of which your Workflow is failing to update some values somewhere down your code line. If yes, then make your code burn through the lock (this should be done using utmost care). Please try searching MSDN/ Live for good examples of how to go about doing this.

    3.       Are any Custom Event Receivers active on the List/Library you are attaching the Workflow to? If yes, make sure that you are not facing an occasional Code clash with it. For example, you are trying to do an update() from your Workflow Code and you are handling the same conditionally in your Event Receiver code, which fails and both sink together.

    4.       Use SPListItem.SystemUpdate() instead of the Update() method. They work differently. Please refer to MSDN for further clarification. You may also want to look at the SPListItem.SystemUpdate(false).

    5.     If you suspect a particular section of your code is causing the issue, try running that block with elevated privileges using:
    SPSecurity.RunWithElevatedPrivileges(delegate()

    {

        // implementation details omitted

    });

    6.     Together with Point#5 above, try setting the CatchAccessDeniedException property of the SPSecurity class before you delegate with elevated privileges to false, like:
    bool originalCatchValue = SPSecurity.CatchAccessDeniedException;SPSecurity.CatchAccessDeniedException = false;

    try

    {

     SPSecurity.RunWithElevatedPrivileges(delegate()

    {

                // implementation details omitted

    });

    }

    finally

    {

       SPSecurity.CatchAccessDeniedException = originalCatchValue;

    }
    Note: For both points# 5 and 6 above you may have to run user accessible code with raised privileges. Please ensure Security and take a sign off from your Security Team regarding any vulnerabilities you may unknowingly create in the process.

    7.       I had once faced problems with my custom Workflow when I wasn’t ticking the “Start the Workflow when a new item is created” option the workflow wasn't kicking at all and went into some sort of perpetual sleep. Try ticking that. You may need to change your code design/flow for this.

    8.       Try setting the workflow/task job timer to a low value, say every minute instead of the default 5 mins. Please verify that this or any custom job you may have created is not causing any hiccups.

    9.       Please verify that all your Code is marked to be serializable. By all I mean all your Workflow Code as well as all the custom classes that your code may be referring etc.        

    10.   Check if you are getting any exception in your Activity Level which you are handling and you are not throwing back. Lay man's explanation(not technical): SharePoint will never know of this exception, but it will face the same internal exception because all SharePoint processes are essentially asynchronous. So although it gets the exception, it doesn’t know what to do with it and gets puzzled. This may also be the case if you are leaving any exceptions unhandled making SharePoint go crazy. Just re-scan through your exception handling mechanism once more. Just once more.


    Somak MSFT
  • Wednesday, June 24, 2009 2:26 AMkuke Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    We are still getting the "ERROR: request not found in the TrackedRequests" error at random times on our State Machine workflow.

    Is there any specific advice on how to fix this error?
  • Thursday, June 25, 2009 4:58 AMkuke Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Additionally, we are receiving a ThreadAbortException when we try to bulk approve tasks (i.e. enumerate tasks for this workflow and call AlterTask on each item):

    System.Threading.ThreadAbortException: Thread was being aborted.
       at System.Threading.Thread.SleepInternal(Int32 millisecondsTimeout)
       at Microsoft.SharePoint.Workflow.SPWorkflowTask.AlterTask(SPListItem task, Hashtable htData, Boolean fSynchronous)

    • Edited bykuke Thursday, June 25, 2009 4:59 AMFix font
    •  
  • Friday, July 03, 2009 5:38 AMDavid S 17 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I am also experiencing the same issue. I have developed a state machine workflow using VS 2008 that has been in production and working for some months now and completes successfully the majority of the time, although I have just found a small number of tasks that have been updated with the onTaskChanged event not firing.

    Hopefully someone will be able to work out the cause of this as I need to get it working 100% of the time!

    Any info appreciated.

    Thanks

    David
  • Friday, July 03, 2009 10:54 AMPaulSmithLondon Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    We are experiencing the same problem using a Nintex workflow.  What I am not sure of is what it actually means in practice.  The workflow seems on the whole to be doing what we want - although we think there may be some random errors.

    Surely someone at Microsoft must have a better idea what is happening here with so many people getting this error?
  • Monday, July 13, 2009 2:27 PMYonatann Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I'm facing similar bahaviour. Developing custom WF with VS 2008, my CreateTaskWithContentType, OnTaskChanged and OnTaskCompleted have the same correlation token, the WF can work just fine for hours, then suddenly the onTaskChanged is not firing at all. When trying to access that task later - it is locked.
    I'm having similar log entries as those provided by other users above. What's killing me is the inconsistency style of this error, it happens in different places in the WF (I have different blocks of task assigning and listening), and occurs randomly.

    Since so many are complaining about this issue, clearly everyone's code is correct (since the WF run successfully most of the time), Can someone from MS have a look at this issue or provide some tool to check what is going on behind?


    ...
  • Thursday, September 03, 2009 12:55 PMW0uter Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Same problem here. The majority (> 90%) of the workflows run as expected but some get stuck.
    I've build quite a few complex workflows for clients. This is the first time I encounter the problem. Luckily it's on our own intranet.

    I added logging at the start and end of every method in my workflow.
    When it gets stuck it is always after (successfully) invoking the method on the 'CreateTask' Activity.

    The next activity is a 'LogToHistory' activity but his method never gets invoked.

    It seems that the workflow engine never gets the 'event/command' to execute the next activity in the workflow.

    Below you find the error that I find in my MOSS logs

    Regards
    W


    RunWorkflow: System.ArgumentException: Item has already been added. Key in dictionary: '193ccecc-4d0c-4cf5-b80d-8e9364ae79f4'  Key being added: '193ccecc-4d0c-4cf5-b80d-8e9364ae79f4'     at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)     at System.Collections.Hashtable.Add(Object key, Object value)     at System.Collections.Hashtable.SyncHashtable.Add(Object key, Object value)     at Microsoft.SharePoint.Workflow.SPWorkflowManager.TrackCreatedInstance(Guid trackingId, SPWorkflow workflow)     at Microsoft.SharePoint.Workflow.SPWorkflowManager.RunWorkflowElev(SPWorkflow originalWorkflow, SPWorkflow workflow, Collection`1 events, SPRunWorkflowOptions runOptions) 
    AutoStart Workflow: System.ArgumentException: New instances of this workflow template are currently disallowed.     at Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflowElev(SPListItem item, SPFile file, SPWorkflowAssociation association, SPWorkflowEvent startEvent, Boolean bAutoStart, Boolean bCreateOnly)     at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.AutoStartWorkflow(SPItemEventProperties properties, Boolean bCreate, Boolean bChange, AssocType atyp) 
    ERROR: request not found in the TrackedRequests. We might be creating and closing webs on different threads. ThreadId = 8, Free call stack =    at Microsoft.SharePoint.SPRequestManager.Release(SPRequest request)     at Microsoft.SharePoint.SPSite.Close()     at Microsoft.SharePoint.SPSite.Dispose()     at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.AutoStartWorkflow(SPItemEventProperties properties, Boolean bCreate, Boolean bChange, AssocType atyp)     at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.AutoStartWorkflow(SPItemEventProperties properties, Boolean bCreate, Boolean bChange)     at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.ItemAdded(SPItemEventProperties properties)     at Microsoft.SharePoint.SPEventManager.RunItemEventRec... 
    ...
  • Thursday, September 03, 2009 11:44 PMJeets Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed AnswerHas Code

    We exactly had the same problem & resolved this issue by.
    Replacing OnTaskCreated activity with OnTaskChanged activity
    Create a  event receiver "ItemAdded" attached to the Task List and include the code as given blow.

    public override void ItemAdded(SPItemEventProperties properties){try{SPWorkflowTask.AlterTask(properties.ListItem, null, false);}catch (Exception ex){Helper.GetExMessage(ex);}}

    This will execute the OnTaskChanged activity & the workflow will treat this activity exactly same as OnTaskCreated activity. 
    Using task object properties one can retrieve any task item fields.
    Make sure you, you execute the same piece of code on OnTaskChanged activity as you doing on OnTaskCreated activity.

    I tried All the proposed Microsoft fixes & none of them worked, but after a few trials I realized OnTaskChanged activity can do the required job.

    Hope this helps!!!

    • Proposed As Answer byJeets Thursday, September 03, 2009 11:44 PM
    •  
  • Thursday, September 03, 2009 11:47 PMJeets Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed AnswerHas Code
    I thought I would add myself to the list here. My problem seems nearly identical to CiBiaR, except I am not even using a custom task form. The problem DOES seem random (between builds) and an additional detail I have not seen posted here would be the following:

    1. Workflow starts and creates task
    2. If the problem task is edited, the changes made in the UI show up in sharepoint just fine; however, the task is now locked by sharepoint and nothing after OnTaskCreated (including the OnTaskCreated_Invoked method) will fire.
    3. At this point, the entire workflow seems to become disconnected from sharepoint meaning: if any other tasks were created in parallel, editing them now results in the same total unresponsiveness / locking (even if the normally work just fine when completed ahead of the problem task).

    I HAVE gone through my designer.cs code and verified that the task token is not being recreated or duplicated.

    Example:
    ------

    this.OnTaskCreated_CreateADAccount.CorrelationToken = correlationtoken20;   
    this.OnTaskCreated_CreateADAccount.Executor = null;   
    this.OnTaskCreated_CreateADAccount.Name = "OnTaskCreated_CreateADAccount";  
     


    ------

    correlationtoken20 is used for OnTaskCreated, OnTaskChanged, etc...

    An excerpt from my ULS log:
    Engine RunWorkflow: System.Workflow.Activities.EventDeliveryFailedException: Event "OnTaskCreated" on interface type "Microsoft.SharePoint.Workflow.ITaskService" for instance id "6074c83e-d0ce-4de7-add4-2abf84f0a5ad" cannot be delivered. ---> System.NullReferenceException: Object reference not set to an instance of an object.     at Microsoft.SharePoint.Workflow.SPWorkflowHostServiceBase.LoadInstanceData(Guid instanceId, Boolean& compressedData)     at Microsoft.SharePoint.Workflow.SPWinOePersistenceService.LoadWorkflowInstanceState(Guid instanceId)     at System.Workflow.Runtime.WorkflowRuntime.InitializeExecutor(Guid instanceId, CreationContext context, WorkflowExecutor executor, WorkflowInstance workflowInstance)     at System.Workflow.Runtime.WorkflowRuntime.Load(Guid key, CreationContext context, WorkflowInstance workflowInstance)     at System.Workflow.Runtime.WorkflowRuntime.GetWorkflow(Guid instanceId)     at System.Workflow.Activities.WorkflowMessageEventHandler.EventHandler(Object sender, ExternalDataEventArgs eventArgs)     --- End of inner exception stack trace ---     at System.Workflow.Activities.WorkflowMessageEventHandler.EventHandler(Object sender, ExternalDataEventArgs eventArgs)     at Microsoft.SharePoint.Workflow.SPWinOETaskService.RaiseEvent(SPWinOeWorkflow workflow, SPWorkflowEvent workflowEvent, Object workItem, IPendingWork workHandler)     at Microsoft.SharePoint.Workflow.SPWinOeHostServices.Send(SPWinOeWorkflow winoeworkflow, SPWorkflowEvent e)     at Microsoft.SharePoint.Workflow.SPWinOeEngine.RunWorkflow(Guid trackingId, SPWorkflowHostService host, SPWorkflow workflow, Collection`1 events, TimeSpan timeOut)

    We exactly had the same problem & resolved this issue by.
    Replacing OnTaskCreated activity with OnTaskChanged activity
    Create a  event receiver "ItemAdded" attached to the Task List and include the code as given blow.

    public override void ItemAdded(SPItemEventProperties properties){try{SPWorkflowTask.AlterTask(properties.ListItem, null, false);}catch (Exception ex){Helper.GetExMessage(ex);}}

    This will execute the OnTaskChanged activity & the workflow will treat this activity exactly same as OnTaskCreated activity. 
    Using task object properties one can retrieve any task item fields.
    Make sure you, you execute the same piece of code on OnTaskChanged activity as you doing on OnTaskCreated activity.

    I tried All the proposed Microsoft fixes & none of them worked, but after a few trials I realized OnTaskChanged activity can do the required job.

    Hope this helps!!!


    • Proposed As Answer byJeets Thursday, September 03, 2009 11:47 PM
    •