More in this section

Forums / Developing with Sitefinity / DateFieldElement Null Exception

DateFieldElement Null Exception

2 posts, 0 answered
  1. Marc
    Marc avatar
    24 posts
    Registered:
    09 Jun 2011
    08 Jul 2011
    Link to this post
    When installing a module, I am getting the following exception on a DateFieldElement:

    System.ArgumentNullException was unhandled by user code
      Message=Value cannot be null.
    Parameter name: key
      Source=mscorlib
      ParamName=key
      StackTrace:
           at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
           at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
           at Telerik.Sitefinity.Configuration.ConfigElementDictionary`2.Add(TKey key, TElement element)
           at Telerik.Sitefinity.Configuration.ConfigElementDictionary`2.Add(TElement element)
           at Article.Web.UI.ArticlesDefinitions.CreateBackendSections(DetailFormViewElement detailView, FieldDisplayMode displayMode) in C:\Program Files (x86)\Telerik\Sitefinity 4.1\Projects\Article\Web\UI\ArticlesDefinitions.cs:line 1181
           at Article.Web.UI.ArticlesDefinitions.DefineArticlesBackendContentView(ConfigElement parent) in C:\Program Files (x86)\Telerik\Sitefinity 4.1\Projects\Article\Web\UI\ArticlesDefinitions.cs:line 903
           at Article.Configuration.ArticlesConfig.InitializeDefaultViews(ConfigElementDictionary`2 contentViewControls) in C:\Program Files (x86)\Telerik\Sitefinity 4.1\Projects\Article\Configuration\ArticlesConfig.cs:line 28
           at Telerik.Sitefinity.Modules.GenericContent.Configuration.ContentModuleConfigBase.OnPropertiesInitialized()
           at Telerik.Sitefinity.Configuration.ConfigElement.InitializeProperties()
           at Telerik.Sitefinity.Configuration.ConfigSection.InitializeProperties()
           at Telerik.Sitefinity.Configuration.ConfigElement.EnsurePropertiesInitialized()
           at Telerik.Sitefinity.Configuration.ConfigElement.get_Properties()
           at Telerik.Sitefinity.Configuration.ConfigElement.get_Item(String propertyName)
           at Telerik.Sitefinity.Modules.GenericContent.Configuration.ContentModuleConfigBase.get_ContentViewControls()
           at Telerik.Sitefinity.Services.ModuleBase.InstallContentViews(SiteInitializer initializer, Version upgradeFrom)
           at Telerik.Sitefinity.Services.ModuleBase.Install(SiteInitializer initializer, Version upgradeFrom)
           at Telerik.Sitefinity.Services.SystemManager.InitializeModule(ModuleSettings settings, InstallContext installContext, Boolean start)
      InnerException:


    The date Field element is defined like so:

    var targetPublishDateField = new DateFieldElement(mainSection.Fields)
               {
                   ID = "targetPublishDateField",
                   Title = "TargetPublishDate",                
                   FieldType = typeof(Controls.Resources.DatePickerField),
                   DisplayMode = displayMode,
                   ResourceClassId = typeof(ArticlesResources).Name,
                   WrapperTag = HtmlTextWriterTag.Li,
                   CssClass = "sfFormSeparator",
                   Value = DateTime.UtcNow
               };
               mainSection.Fields.Add(targetPublishDateField);

    The error is thrown when adding mainSection.Fields.Add(targetPublishDateField) line is hit.  The only thing I can see is possibly because I am using a custom Field I built called DatePickerField in the FieldType.  Thoughts?  Other standard controls are not tossing the error so that is all I can think.
  2. Marc
    Marc avatar
    24 posts
    Registered:
    09 Jun 2011
    08 Jul 2011
    Link to this post
    Ok, looks like I just needed to set the DataFieldName when creating the DateFieldElement.

    var targetPublishDateField = new DateFieldElement(mainSection.Fields)
                {
                    ID = "TargetPublishDate",
                    Title = "TargetPublishDate",           
                    DataFieldName = "TargetPublishDate",
                    FieldType = typeof(Controls.Resources.DatePickerField),                
                    DisplayMode = displayMode,
                    ResourceClassId = typeof(ArticlesResources).Name,
                    WrapperTag = HtmlTextWriterTag.Li,
                    CssClass = "sfFormSeparator",
                    Value = DateTime.UtcNow
                };
      
                mainSection.Fields.Add(targetPublishDateField)

    On a different note, how do I mark my own posts as solved/closed since I resolved my own issue?
2 posts, 0 answered