Symptoms
Within SharePoint 2013, when adding a form viewer app part to a particular K2 activated site collection, no forms are listed. Attempting to use the search bar throws this error. Using the app part on a different site collection lists forms for selection.
Error: Object reference not set to an instance of an object.
?Type: SourceCode.SmartObjects.Client.SmartObjectException
?Source: SourceCode.SmartObjects.Client
?Method Base
?Member Type: Method
?Name: GetSmartObjectReader
?Module
?Scope Name: SourceCode.SmartObjects.Client.dll
?Declaring Type
?Full Name: SourceCode.SmartObjects.Client.SmartObjectClientServer
?Stack Trace:
at SourceCode.SmartObjects.Client.SmartObjectClientServer.GetSmartObjectReader(SmartObject smartObject, ExecuteListReaderOptions options, Dictionary`2andamp propertyReference)
at SourceCode.SmartObjects.Client.SmartObjectClientServer.ExecuteListReader(SmartObject smartObject, ExecuteListReaderOptions options)
at SourceCode.Forms.AppFramework.FormsApiToXml.ToXmlList()
at SourceCode.Forms.AppFramework.FormRuntime.SmartObjectExecution(XPathNavigator nav, Boolean outputDependencies, SmartObjectClientServer svr)
at SourceCode.Forms.AppFramework.FormRuntime.WorkXmlToApi(String xml)
at SourceCode.Forms.Runtime.AJAXCall.ProcessRequest(HttpContext context)
Diagnoses
The issue has been identified and does in fact involve orphaned data (forms and views) in your K2 database. There are a handful of forms that are mapped to categories that do not exist.
Resolution
A script has been developed that will move the forms to a new category (contact k2 support for script). Sent script, along with a set of steps which include the following:
1. Take a backup of the K2 database prior to running anything against it
2. Run the script, defining the variable @CategoryName as an item of your choosing. This will be at the top of the script in the second line. This will basically move all the orphaned items into a new category so that when the smartobject call is made to load the Form Viewer's categories, it doesn't fail saying "I don't know where to place these other objects" more or less.
3. Reload the page containing the Form Viewer webpart and see that it loads properly.
The script provided in this case forced orphaned items to be relocated into a new folder so that the categories could successfully be queried. This seemed to resolve the issue. The script can be modified to move orphaned views and forms to a specified folder. If need, these orphaned view/forms might need to be removed if their are new version of them are available the they are duplicates.