Object reference not set to an instance of an object.

Vote:
 
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?
#13033
Mar 25, 2008 18:35
Vote:
 
Sorted it out, forgot to set the dynamic property to Page. :)
#15282
Mar 25, 2008 18:46
Vote:
 
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; } }
#15283
Mar 25, 2008 18:46
Vote:
 
Managed to sort that out to. :)
#15284
Mar 25, 2008 18:46
* 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.