Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I've made a workflow in Designer which I invoke trough code in Visual studio. The solution is working fine in my Development machine, but when I implement to the production I get an error:

Object reference not set to an instance of an object.

Codesnippet for starting the workflow:

SPWorkflowAssociation wfAssoc = item.ParentList.WorkflowAssociations.GetAssociationByName(workflowname, System.Globalization.CultureInfo.CurrentCulture);
item.Web.Site.WorkflowManager.StartWorkflow(item, wfAssoc, wfAssoc.AssociationData, true);

Edited

share|improve this question
    
Kashi, what do you have in wfAssoc.AssociationData.. Make sure it is not null or empty string... have a look here –  Arsalan Adam Khatri Oct 22 '12 at 11:04
    
thanks for your reply, actually I came around this problem by starting the worlkflow, trough Sharepoint Designer start workflow when new Item created, and then I had Another Eventreciver in the code,Itemupdated, which also cancel the workflow on a item and start it again and then I'm able to start the workflow by code. My solution is a approval process which have to repeated until the item is approved. So it's seem the workflow from Sharepoint Designer is loaded after my code??? –  kashi Oct 23 '12 at 7:35
    
Kashi, it seems like you are trying to achieve a While loop inside a workflow and here is an article for custom activity, you can use it with both MOSS 2007 and SharePoint 2010 –  Arsalan Adam Khatri Oct 23 '12 at 7:50
    
Arslan, no I'm not using a while loop but It operates like a while loop. I have an eventreciver which checks if the item is updated and then it cancel all the worklflow associated with the item and restart the workflow. So this way I get a kind of while loop. –  kashi Oct 24 '12 at 8:39

2 Answers 2

The error means some of your variables are null.

You could add checks for item, since you call .Web on it and wfAssoc since you call .AssociationData on that.

My best guess is that wfAssoc is null.

share|improve this answer
    
thanks for your reply, it seems that the workflow is loaded after the code, in debugging mode an exeption is thrown but later when I uptade the page I see that workflow action have been done. But I came around this plz see me comment above –  kashi Oct 23 '12 at 7:42

After applying Service Pack 1 the workflows created in SharePoint designer that should launch under the credentials of the system account will no longer start automatically. (including when it is called from code which is running under elevated privileges).

Additionally, if you email-enable a document library and attach a workflow to it, and set the workflow to start on Item creation, this workflow will never start.

Check out below article, if this is something related to your issue.

Workflows do not start

Hope it helps!!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.