More in this section
Forums / Sitefinity SDK / HierarchicalTaxonFieldDefinitionElement: null reference exception

HierarchicalTaxonFieldDefinitionElement: null reference exception

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
1 posts, 0 answered
  1. jocelyn payneau
    jocelyn payneau avatar
    51 posts
    07 Dec 2009
    17 Feb 2011
    Link to this post

    I create a new taxonomy in the module installation and I want to display its content using a HierarchicalTaxonFieldDefinitionElement.

    Here is the code i'm using:
    var taxonomyManager = TaxonomyManager.GetManager();
                var marketsField = new HierarchicalTaxonFieldDefinitionElement(mainSection.Fields)
                    ID = "marketsFieldControl",
                    DisplayMode = displayMode,
                    Title = Res.Get<ContactsResources>().SelectMarkets,
                    ResourceClassId = typeof(ContactsResources).Name,
                    TaxonomyId = new Guid("9A7FF96D-1D99-4fd9-ADB8-714E1A0F3272"),
                    TaxonomyProvider = taxonomyManager.Provider.Name,
                    WebServiceUrl = "~/Sitefinity/Services/Taxonomies/HierarchicalTaxon.svc",
                    AllowMultipleSelection = true,
                    FieldType = typeof(HierarchicalTaxonField),
                    WrapperTag = HtmlTextWriterTag.Li
                marketsField.ValidatorConfig = new ValidatorDefinitionElement(marketsField)
                    Required = true,
                    MessageCssClass = "sfError",
                    RequiredViolationMessage = Res.Get<ContactsResources>().YouMustSelectAMarket

    I got a null reference exception on the last line (mainSection.Fields.Add(marketsField)). marketsField is not null.
    I don't know what it happens.

    Do you have any idea?

    I solve it, i forgot to declare some attributes...

    But i have a problem with my resources class. I got an error "cannot find key "select one or many market" or resources class id ContactsResources". But my key is SelectMarkets.

1 posts, 0 answered