HierarchicalTaxonFieldDefinitionElement: null reference exception - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

HierarchicalTaxonFieldDefinitionElement: null reference exception

  • HierarchicalTaxonFieldDefinitionElement: null reference exception
  • Hello,

    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
                ;
                mainSection.Fields.Add(marketsField);

    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?

    Edit
    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.

    Jocelyn