"Object Reference not set to an instance of an object" error in K2 Studio or K2 for Visual Studio
kbt133606
PRODUCTIssue
When using K2 Studio or K2 for Visual Studio and expanding the SmartObject Server(s) > SmartObject Server from the Object Browser, an "Object Reference not set to an instance of an object" error is displayed and no SmartObjects are visible in any of the Categories.
Symptoms
The following error message may also be displayed:
Troubleshooting Steps
Execute the following SQL query against the K2 Database:
Use K2 --Change to your K2 Database Name
DECLARE @result1 TABLE (Id INT, CategoryName nvarchar(100), MissingParentID INT)
INSERT INTO @result1
--Select all Categories with missing ParentID
SELECT [Id], [Name],
r.value('@id','int')
FROM [Category].[Category]
CROSS APPLY [ParentCategories].nodes('/parentcategory[1]') AS x(r)
WHERE r.value('@id','int') not in (SELECT Id FROM [Category].[Category]);
SELECT * FROM @result1;
--Select any Object currently in the Orphaned Category
SELECT * FROM [Category].[Data]
WHERE [CategoryId] in (SELECT Id FROM @result1);
--Select any Object in category that does not exist
SELECT * FROM [Category].[Data]
WHERE [CategoryId] not in (SELECT Id FROM [Category].[Category]);
--Select any Object that does not exist in category
SELECT * FROM [Category].[Data] WHERE [Data] not in (SELECT [SmartObjectGUID] FROM [SmartBroker].[SmartObject]) AND [DataType] = 'SmartObject'
UNION
SELECT * FROM [Category].[Data] WHERE [Data] not in (SELECT [ID] FROM [Form].[Form] UNION SELECT [ID] FROM [Form].[Form_Design]) AND [DataType] = 'Form'
UNION
SELECT * FROM [Category].[Data] WHERE [Data] not in (SELECT [ID] FROM [Form].[View] UNION SELECT [ID] FROM [Form].[View_Design]) AND [DataType] = 'View'
Under normal circumstances, no data should be displayed on any of the results.
Should the results display data, it would indicate orphaned Categories and/or K2 Objects, which is the cause of the error.
To resolve this issue, direct database modification will be required. Please log a K2 Support Ticket on the K2 Customer Portal for assistance in resolving the issue.