Workflow Woes 

Tags: SharePoint

I have been working on a workflow solution for a client. Having looked over their existing solution, my first impression was that we could replicate the same functionality using only some custom lists and maybe a field control or two. Then I got some additional requirements, and now it is more clear that they need some InfoPath forms around teh item creation workflow to make sure different people all provide their little slice of information.
 
So, I have been folllowing Nick Swan's walkthrough on creating a custom workflow in VS.net. At first I was following along great. Everything seems very much as if it were done in BizTalk, which I know pretty well, but I started running into issues during deployment.
 
My first mistake was a no brainer, but it did trip me up for a minute. In teh FEATURE.XML file, there is an attribute called Hidden that does not get included in the code snippit. If you want your feature to show up in the web admin, you'll need to make htis FALSE. Of course the vs.net post-deployment task will actually activate the feature for you too - I think - but this did not stop me from scratching my head for a few minutes anyway.
 
The next issue is that the sample workflow will only work with Scope=Site (that's as in "SPSite" not "web site" by the way). I don't know why this is. Maybe the standard Microsoft provided feature receiver can't handle workflows that are designed this way in the web context? In any case, changing the FEATURE.XML back to Scope=Site got me through this problem.
 
What will happen if you try to activate the feature at the Web (web site) level is that you will see in the LOGS folder that FeatureReceiver.FeatureActivated is called and throws an NullReferenceException (e.g. "object reference not set" exception). Here are the details from the log file:
 

Calling 'FeatureActivated' method of SPFeatureReceiver for Feature 'SeqWorkflowLab1' (ID: 'cff78dbc-0e13-40f1-a648-91a44c7e7da1').               

10/10/2007 10:32:28.98 w3wp.exe (0x090C)                       0x0354  Windows SharePoint Services   Feature Infrastructure                        88jm      High       Feature receiver assembly 'Microsoft.Office.Workflow.Feature, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c', class 'Microsoft.Office.Workflow.Feature.WorkflowFeatureReceiver', method 'FeatureActivated' for feature 'cff78dbc-0e13-40f1-a648-91a44c7e7da1' threw an exception: System.NullReferenceException: Object reference not set to an instance of an object.     at Microsoft.Office.Workflow.Feature.WorkflowFeatureReceiver.FeatureActivated(SPFeatureReceiverProperties properties)     at Microsoft.SharePoint.SPFeature.DoActivationCallout(Boolean fActivate, Boolean fForce)       

 

Feature Activation: Threw an exception, attempting to roll back.  Feature 'SeqWorkflowLab1' (ID: 'cff78dbc-0e13-40f1-a648-91a44c7e7da1').  Exception: System.NullReferenceException: Object reference not set to an instance of an object.     at Microsoft.Office.Workflow.Feature.WorkflowFeatureReceiver.FeatureActivated(SPFeatureReceiverProperties properties)     at Microsoft.SharePoint.SPFeature.DoActivationCallout(Boolean fActivate, Boolean fForce)     at Microsoft.SharePoint.SPFeature.Activate(SPSite siteParent, SPWeb webParent, SPFeaturePropertyCollection props, Boolean fForce)               

 

Exception Type: System.NullReferenceException  Exception Message: Object reference not set to an instance of an object.                  
 
Ok. Got through that. Next issue.
 
Silly me, I never upgraded my SharePoint to Enterprise edition. So, I picked through my license keys from MSDN and found the code to activate the upgrade. Then I had to activate the enterprise features in the existing sites, and do an iisreset. No biggie, but I should've done this a while ago.
 
So now my workflow is fully activated and it appears in the list of workflows when I go to List Settings > Workflow Settings. I enter all the appropriate info, and check [or don't] the "Start this workflow when a new item is created." checkbox.
 
A box comes back that says, "The specified form cannot be found." What gives? So, I go into Central Adminsitration > Application Management under the section called InfoPath Forms Services there is a link called "manage form templates". In there I do see my two new forms, which is good. I don't know if they've been activated to work with a specific site collection, and I am suspecting they haven't been, but as it turned out you can't do this because these are workflow forms. So, moving on, why can't the list "see" my form?
 
Well, I did a little reading and I found that many people are having problems with this error. The primary cause is that their FEATURE.XML and WORKFLOW.XML are not set up correctly and therefore they are not actually deploying the needed XSN files to the server. But this is not my issue.
 
Eureka! I've found it. Watch out for this when you create and publish your InfoPath forms. It seems that the URN (unique ID) is changed each time you publish the form.
 
Compare this from the XSN in my IP project folder:
urn:schemas-microsoft-com:office:infopath:WorkflowLab1-InfoPath1:-myXSD-2007-09-28T18-41-02
With this from my XSN that I places in the Features folder:
urn:schemas-microsoft-com:office:infopath:Initiation-Form:-myXSD-2007-09-28T18-41-02
Also, notice the timestamp! It's possible this changes every time you publish a new version, which would mean updating your XML every time you make a change to the form.
 
Update:
 
Okay, so I finally get everything installed properly and now I am able to associate my workflow with a list. The association form is ugly as hell and doesn't make any sense because it is the same as the initiation form, but that's ok for now.
 
However, I am getting a SerializationException when I attempt to create a new object, and the workflow terminates. At least now it is in my code, and I know what is going on, because my workflow is trying to deserialize the XML that comes from the InfoPath initiation form.
 
Digging into the autogenerated class produced by XSD gives me a good explanation for why it would not work. There are anyAttribute properties peppered all over it. This is doubly complicated by the fact that I used a rich edit control in my IP form.
 
So, rather than try to kit bash the sample into doing what I want or willy-nilly commenting out parts of the class file every time I change the XSD, I've decided to go back to a best practice that I used to follow in IP/SharePoint 2003. I will be creating my XSD file first - by hand, and then beinding my IP form to it after it has been defined and the class files have been generated. Also, I think I will use XsdObjectGen instead of xsd.exe because I think it generates code that is easier for a developer to use. (Actually it won't be by hand. I like to use the BizTalk XSD editor to do this.) In my mind this is the essence of the contract first principle of SOA.
 
Update II:
 
Laziness may win in the end, because I really would like to see this work.
 
Upon further reflection and looking at the stack trace, I decided that maybe the serialization error isn't happening exactly where I think it is. Is it possible that the InfoPath schema deserializes correctly and my mistake is then in assigning its properties to my workflow instance's ExtendedProperties collection?
 
WinWF Internal Error, terminating workflow Id# cb38d1cb-e216-488a-9cc3-f9a1df33129d 
10/10/2007 12:32:24.51  w3wp.exe (0x126C)                        0x0558 Windows SharePoint Services    Workflow Infrastructure        98d4 Unexpected System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: The platform does not know how to deserialize an object of type Instructions. The platform can deserialize primitive types such as strings, integers, and GUIDs; other SPPersistedObjects or SPAutoserializingObjects; or collections of any of the above. Consider redesigning your objects to store values in one of these supported formats, or contact your software vendor for support.     at Microsoft.SharePoint.Administration.SPAutoSerializingObject.DeserializeBasicObject(XmlElement xmlValue)     at Microsoft.SharePoint.Administration.SPAutoSerializingObject.DeserializeBasicObject(XmlElement xmlValue)     at Microsoft.SharePoint.Administration.SPAutoSerial... 
10/10/2007 12:32:24.51* w3wp.exe (0x126C)                        0x0558 Windows SharePoint Services    Workflow Infrastructure        98d4 Unexpected ...izingObject.SetStateXml(XmlNodeList childNodes)     at Microsoft.SharePoint.Administration.SPAutoSerializingObject.SetStateXml(XmlDocument value)     at Microsoft.SharePoint.Administration.SPAutoSerializingObject..ctor(SerializationInfo info, StreamingContext context)     at Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties..ctor(SerializationInfo info, StreamingContext context)     --- End of inner exception stack trace ---     at System.RuntimeMethodHandle._SerializationInvoke(Object target, SignatureStruct& declaringTypeSig, SerializationInfo info, StreamingContext context)     at System.RuntimeMethodHandle.SerializationInvoke(Object target, SignatureStruct declaringTypeSig, SerializationInfo info, StreamingContext context)     at System.Reflection.RuntimeConstructorInfo.Serializat... 
10/10/2007 12:32:24.51* w3wp.exe (0x126C)                        0x0558 Windows SharePoint Services    Workflow Infrastructure        98d4 Unexpected ...ionInvoke(Object target, SerializationInfo info, StreamingContext context)     at System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context)     at System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder holder)     at System.Runtime.Serialization.ObjectManager.DoFixups()     at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)     at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)     at System... 
10/10/2007 12:32:24.51* w3wp.exe (0x126C)                        0x0558 Windows SharePoint Services    Workflow Infrastructure        98d4 Unexpected ....Workflow.Activities.InvokeHelper.CloneOutboundValue(Object source, BinaryFormatter formatter, String name)     at System.Workflow.Activities.InvokeHelper.GetParameters(MethodBase methodBase, WorkflowParameterBindingCollection parameterBindings, ParameterModifier[]& parameterModifiers)     at System.Workflow.Activities.CallExternalMethodActivity.Execute(ActivityExecutionContext executionContext)     at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext)     at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(Activity activity, ActivityExecutionContext executionContext)     at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime)     at System.Workflow.Runtime.Scheduler.Run... 
10/10/2007 12:32:24.51* w3wp.exe (0x126C)                        0x0558 Windows SharePoint Services    Workflow Infrastructure        98d4 Unexpected ...() 
 

Links to this post

Comments

Make a Comment

Name *:
URL:
Email:
Comments:

`