2015-12-22

NullReferenceException When Clicking a Task in Workflow Designer

The other day I was designing a Workflow (Workflow Manager technology) in Visual Studio 2012 when I stumbled upon on an exception when clicking on a SingleTask activity in Workflow Designer within Visual Studio. When I first click on a task I get "Communicating with SharePoint" dialog:


After Visual Studio establishes communication with SharePoint I end up with the following dialog:

Full exception stack trace is as follows:
-------------------------
Workflow Designer
-------------------------
NullReferenceException:
Object reference not set to an instance of an object.
-------------------------

Server stack trace:
   at Microsoft.VisualStudio.SharePoint.Designers.List.ModelAccess.SharePointSolutionModelStorage.GetAllFiles(ISharePointProject project)
   at Microsoft.VisualStudio.SharePoint.Designers.List.ModelAccess.SharePointSolutionModelStorage.Refresh(ISharePointProject project)
   at Microsoft.VisualStudio.SharePoint.Designers.List.ModelAccess.SharePointCompositeModelStorage.RefreshProjectModels()
   at Microsoft.VisualStudio.SharePoint.WorkflowDesignerSupport.ListInfoService.GetContentTypes(String BaseTypeId)
   at Microsoft.VisualStudio.SharePoint.WorkflowExtensions.SharePointListService.<GetWorkflowTaskContentTypes>b__10(IListInfoService service)
   at Microsoft.VisualStudio.SharePoint.WorkflowExtensions.SharePointListService.ConvertValues(Func`2 producer)
   at Microsoft.VisualStudio.SharePoint.WorkflowExtensions.SharePointListService.GetWorkflowTaskContentTypes()
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Microsoft.SharePoint.DesignTime.Activities.Design.Services.ISharePointListService.GetWorkflowTaskContentTypes()
   at Microsoft.SharePoint.DesignTime.Activities.Design.ContentTypesProvider.ProvideItems(ISharePointListService service)
   at Microsoft.SharePoint.DesignTime.Activities.Design.IndependentDataProvider`1.GetItems(ModelItem owner, PropertyValue propertyValue)
   at Microsoft.SharePoint.DesignTime.Activities.Design.SharePointItemChooserViewModel`1.GetItems(ModelItem Owner, PropertyValue PropertyValue)
   at Microsoft.SharePoint.DesignTime.Activities.Design.ChooserViewModel`1.PopulateItems()
   at Microsoft.SharePoint.DesignTime.Activities.Design.GenericChooser`2.SharePointBaseChooser_Loaded(Object sender, RoutedEventArgs e)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.RouteItem.InvokeHandler(RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.EventRoute.InvokeHandlers(Object source, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
   at MS.Internal.LoadedOrUnloadedOperation.DoWork()
   at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
-------------------------


After a long debugging session of Workflow Designer I realized that my colleague accidentally deleted Package folder from SharePoint App project. I pulled the latest version and I didn't notice that folder was missing. When I restored the folder, Workflow Designer didn't throw any exceptions any more.

2015-12-03

Running a Project with Workflow in Provider-Hosted Add-In

While trying to run (F5 in Visual Studio) add-in project of provider-hosted add-in containing workflow I got this error in output window:

Microsoft.SharePoint.WorkflowServices
System.FormatException: RestrictAssociationToId   
 at Microsoft.SharePoint.WorkflowServices.DGWorkflowDeploymentProvider.PublishOrUpdateDefinitions(WorkflowServicesManager proxy, WorkflowDeploymentService deploymentService, Dictionary`2 oldDefinitionIdMap, Dictionary`2 newDefinitionIdMap, Dictionary`2 listIdDictionary)   
 at Microsoft.SharePoint.WorkflowServices.DGWorkflowDeploymentProvider.DeployOrUpgrade(WorkflowScopeIdentifier scopeId, SPWorkflowPart oldParts, SPWorkflowPart newParts, Dictionary`2 listIdDictionary)   
 at Microsoft.SharePoint.WorkflowServices.DGWorkflowDeploymentProvider.Deploy(WorkflowScopeIdentifier scopeId, SPWorkflowPart parts, Dictionary`2 listIdDictionary) StackTrace:
 at Microsoft.Office.Server.Native.dll: (sig=678c0f87-966f-4d99-9c94-b49e788d2672|2|microsoft.office.server.native.pdb, offset=131CE)
 at Microsoft.Office.Server.Native.dll: (offset=21BE5)


Turns out I didn't include target list and history list in the app feature. This caused aforementioned error while trying to deploy workflow during "Activate features" stage. As soon as I included the lists in the feature everything went ok.