Object reference not set to an instance of an object.

I'm trying to develop a small plugin for EPi-Server. I've based my solution on the Languages plugin. I'm stuck at an error I can't seem to resolve. Tried to use Google. Properties.cs Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 79: Line 80: DynamicProperty prop = DynamicProperty.Load(EPiServer.Global.EPConfig.StartPage, "ColourList"); Line 81: PageReference colourRef = (PageReference)prop.PropertyValue.Value; Line 82: Line 83: if (colourRef == PageReference.EmptyReference) Any ideas?
May 09, 2007 13:09
Sorted it out, forgot to set the dynamic property to Page. :)
May 09, 2007 13:33
Attributes (id: 165) -> Materials (id: 295) -> Wood -> etc -> etc -> Colours (id: 406) -> Bla -> Bla It just lists “Materials” and “Colours” in the checkbox-list at the editor even tho i’m pointing the Page-reference to Materials. I’ve checked the GetChildren-function and it should work properly shouldn’t it? Here is the code: public void BuildPages() { _selectedPages = new PageDataCollection(); //= if there is no saved value, there are no selected pages if(String.Length == 0) return; String[] pageIds = String.Split(','); PageData page = null; //= iterate through the ids stored in string and try to create a PageData //= object. If we succeed, add page to the _selectedPages foreach (String pageId in pageIds) { page = EPiServer.Global.EPDataFactory.GetPage( new PageReference( int.Parse(pageId) ) ); if ( page != null) _selectedPages.Add(page ); } } /// /// /// /// /// private bool PageIsContained(PageData page) { foreach(PageData pageToCheck in _selectedPages) if (pageToCheck.PageLink.ID == page.PageLink.ID) return true; return false; } public override void CreateChildControls(string renderType,System.Web.UI.Control container) { BuildPages(); switch(renderType) { case "edit": //= source the root for the colours from a dynamic property on the //= start page DynamicProperty prop = DynamicProperty.Load(EPiServer.Global.EPConfig.StartPage, "ColourList"); PageReference colourRef = (PageReference)prop.PropertyValue.Value; if (colourRef == PageReference.EmptyReference) throw new Exception("Missing: Dynamic ColourList as a Page Reference"); //= get the children of the dynamic property as our list of colours PageDataCollection pages = EPiServer.Global.EPDataFactory.GetChildren(colourRef); //= add each colour to the checkbox list CheckBoxList propertyList = new CheckBoxList(); propertyList.RepeatColumns = 5; foreach(PageData page in pages) { ListItem item = new ListItem(page.PageName, page.PageLink.ID.ToString()); //= if the page (colour) is in the selectedPages, then selected = true item.Selected = PageIsContained( page); propertyList.Items.Add(item); } CopyWebAttributes(container,propertyList); container.Controls.Add(propertyList); propertyList.Controls.Add(CreateParseValidator(propertyList)); break; default: Label properties = new Label(); StringBuilder builder = new StringBuilder(); foreach(PageData page in _selectedPages) builder.Append(page.PageName).Append(','); CopyWebAttributes(container,properties); if(builder.Length > 0) properties.Text = builder.Remove(builder.Length - 1, 1).ToString(); container.Controls.Add(properties); break; } }
May 10, 2007 14:10
Managed to sort that out to. :)
May 11, 2007 9:08
* 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.