Oh!! its SharePoint again :). One of these small things in this beast which makes you bang your head and pull your hear again and again if you don't get it right. Now lucky you you can search this issue and find the solution.

Debugging in SharePoint is very tricky sometimes because you get all of these levels to run around (GAC + IIS + Deployment Folder under the feature + Feature.xml + Workflow.xml + SharePoint itself + InfoPath the main form template + InfoPath the workflow forms and  Web Services) so after this, it is not strange that you would start pulling your hear after a while.

Problem Description:

if you try any workflow (including OOB WF and Custom WF) and when you try to start it, it will show the message Workflow "Failed on Start (retrying)". You may also see that some tasks in the WF are created and even so it fails.

Tip: whenever you are stuck with your custom workflow, try having the OOB, if it doesn't run, its not your problem. (i spent one complete day almost 20H just to discover its not my fault).

One Proof that this thing its not your custom code problem, if you attach the WF process to Visual Studio, it will not catch any exception.

Reasoning:

In WSS/MOSS the workflow engine will report back 'a workflow failed to start' even if the workflow did start.

The reason why is that - the workflow will be sent the 'OnWorkflowActivated' event (start command) and essentially as far as MOSS is concerned - it's starting.

When the workflow for e.g. writes a task item and then waits (handleExternal Event) for the OnTaskChanged event. At this point if it failed - a different error other than 'failed to start' would be reported.

Resolution:

  • First and importantly check all your correlation tokens. make sure that each task (Creation, Updating and Completing) has its own Token not the workflow token.
  • Then compare the dll you have with theone in the workflow.xml and the one in the GAC. simply they all should be the same.
  • Try this on the command prompt: Lodctr "c:\Windows\Microsoft.Net\Framework\v3.0\Windows Workflow Foundation\perfcounters.ini"
  • And if it doesn't work for you try: Lodctr /R "c:\Windows\Microsoft.Net\Framework\v3.0\Windows Workflow Foundation\perfcounters.ini"

Some Links might Help:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2268844&SiteID=1

Some errors you might see in logs:

  • The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly.
  • Failed on Start (retrying).
  • Unexpected    Load Workflow Class: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly.     at System.Diagnostics.PerformanceCounter.Initialize()     at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName, Boolean readOnly)     at System.Workflow.Runtime.PerformanceCounterManager.CreateCounters(String name)     at System.Workflow.Runtime.Hosting.DefaultWorkflowSchedulerService.OnStarted()     at System.Workflow.Runtime.Hosting.WorkflowRuntimeService.HandleStarted(Object source, WorkflowRuntimeEventArgs e)     at System.EventHandler`1.Invoke(Object sender, TEventArgs e)...    
    01/11/2008 03:33:24.79*    w3wp.exe (0x12B4)                           0x0E9C    Windows SharePoint Services       Workflow Infrastructure
  • Unexpected    ...     at System.Workflow.Runtime.WorkflowRuntime.StartRuntime()     at Microsoft.SharePoint.Workflow.SPWinOeHostServices..ctor(SPSite site, SPWeb web, SPWorkflowManager manager, SPWorkflowEngine engine)     --- End of inner exception stack trace ---     at System.RuntimeMethodHandle._InvokeConstructor(Object[] args, SignatureStruct& signature, IntPtr declaringType)     at System.RuntimeMethodHandle.InvokeConstructor(Object[] args, SignatureStruct signature, RuntimeTypeHandle declaringType)     at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)     at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)     at System.Ac...    
    01/11/2008 03:33:24.79*    w3wp.exe (0x12B4)                           0x0E9C    Windows SharePoint Services       Workflow Infrastructure           72fu    Unexpected    ...tivator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)     at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)     at Microsoft.SharePoint.Workflow.SPWorkflowManager.LoadPluggableClass(String classname, String assembly, Object[] parameters)    
    01/11/2008 03:33:24.80     w3wp.exe (0x12B4)                           0x0E9C    Windows SharePoint Services       Workflow Infrastructure