"Object reference not set to an instance" when calling FindPagesWithCriteria

Vote:
 

 

Hi,

I receive a "Object reference not set to an instance of an object" when calling FindPagesWithCriteria.

I'm trying to select pages based on categories:

PropertyCriteriaCollection criteriaCollection = new PropertyCriteriaCollection();
PropertyCriteria criteriaFindImages = new PropertyCriteria();
criteriaFindImages.Condition = CompareCondition.Equal;

string selectedFolder;
selectedFolder = dropDownCategories.Items[dropDownCategories.SelectedIndex].Text;
criteriaFindImages.Value = selectedFolder;
criteriaFindImages.Type = PropertyDataType.Category;

criteriaCollection.Add(criteriaFindImages);

PageDataCollection pages = new PageDataCollection();
Debug.WriteLine(GetPage(PageReference.StartPage).PageName);
Debug.WriteLine(criteriaCollection.Count);
Debug.WriteLine(CurrentPage.LanguageBranch);

pages = DataFactory.Instance.FindPagesWithCriteria(PageReference.StartPage, criteriaCollection);
The error-message I receive:
[NullReferenceException: Object reference not set to an instance of an object.]
EPiServer.DataAccess.PageDB.IsMetaData(String name) +182
EPiServer.DataAccess.PropertySearchDB.ExecuteCriteria(Int32 pageID, PropertyCriteria criteria, String languageBranch) +984
EPiServer.DataAccess.PropertySearchDB.CriteriaSearch(Int32 pageID, PropertyCriteria criteria, Boolean firstQuery, IList`1 pageLinks, String languageBranch) +39
EPiServer.DataAccess.PropertySearchDB.FindPagesWithCriteria(Int32 pageID, PropertyCriteriaCollection criterias, String languageBranch) +277
EPiServer.DataAbstraction.SearchPages.FindPagesWithCriteria(PageReference pageLink, PropertyCriteriaCollection criterias, String languageBranch, ILanguageSelector selector, AccessLevel requiredAccess) +145
EPiServer.LocalPageStore.FindPagesWithCriteria(PageReference pageLink, PropertyCriteriaCollection criterias, String languageBranch, ILanguageSelector selector, AccessLevel requiredAccess) +40
EPiServer.DataFactory.FindPagesWithCriteria(PageReference pageLink, PropertyCriteriaCollection criterias, String languageBranch, ILanguageSelector selector, AccessLevel requiredAccess) +210
EPiServer.DataFactory.FindPagesWithCriteria(PageReference pageLink, PropertyCriteriaCollection criterias) +82
 
The same problem happens if I try this:
PropertySearchDB search = new PropertySearchDB();
IList refColl =
search.FindPagesWithCriteria(PageReference.StartPage.ID, criteriaCollection, "sv");

 I'm using EPiServer 5.1.422.256.
Has anyone seen this problem before? Any clues how to solve it?
Best regards, 
Peter Bergqvist 
#20273
May 25, 2008 20:59
Vote:
 

You need to set the Name attribute on your PropertyCriteria object :

 criteriaFindImages.Name = "nameofyourproperty";

 

#20274
May 25, 2008 22:16
Vote:
 

Thank you for the quick reply, Mari! Works great!

Has this changed in EPiServer v.5? Where could I read more info on mandatory attributes? 

#20275
May 25, 2008 23:12
Vote:
 

No, this is not new in EPiServer CMS 5 - FindPagesWithCriteria searches for pages based on Property values and require Name, Value, Type and Condition to be set in order to do its search.

Read this excellent blog post for more information:

http://labs.episerver.com/en/Blogs/Ted-Nyberg/Dates/112276/2/Search-for-EPiServer-pages-based-on-properties/ 

/Mari Smile

#20276
May 25, 2008 23:49
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.