+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / SetContent not working in module

SetContent not working in module

6 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    02 Dec 2010
    Link to this post
    Hi,

    I have a module that has a meta key of UserID. This is a the UserId from the Telerik_Users table i.e. an asp.net membership user id.

    In the add view of the module I populate a dropdown list that is within the <contentmetafields> section using a linq query, as so:

    protected override IContent SetContentForm(IContent cnt) {
     
        TnfDataAccess.DAL db = new TnfDataAccess.DAL();
        var sql = from u in db.Telerik_Users
                  let FirstName = (from fname in db.Telerik_UserMetaInfo
                                   where fname.UserId == u.UserId
                                   && fname.PropertyName == "FirstName"
                                   select fname.Text).SingleOrDefault()
                  let LastName = (from fname in db.Telerik_UserMetaInfo
                                  where fname.UserId == u.UserId
                                  && fname.PropertyName == "LastName"
                                  select fname.Text).SingleOrDefault()
                  join uir in db.Telerik_UsersInRoles on u.UserId equals uir.UserId
                  join r in db.Telerik_Roles on uir.RoleId equals r.RoleId
                  where r.LoweredRoleName == "members"
                  select new { u.UserId, FullName = String.Concat(FirstName, " ", LastName) };
     
     
     
        this.oUserDropDownList.DataSource = sql;
        this.oUserDropDownList.DataTextField = "FullName";
        this.oUserDropDownList.DataValueField = "UserId";
        this.oUserDropDownList.DataBind();
     
        return base.SetContentForm(cnt);
     
    }

    However, on the edit view the exact same code produces the followig error:

    Exception Details: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

    Source Error: 

    Line 67:             this.oUserDropDownList.DataBind();
    Line 68: 
    Line 69:             return base.SetContentForm(cnt);
    Line 70: 
    Line 71:         }

    Can anyone provide a reason or solution?

    Thanks in advance
    higgsy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Dec 2010
    Link to this post
    Hi higgsy,

    If you remove your code from the overridden method , do you get this error? The issue seems to be related to the metakeys data. Most probably you have removed some metakey from the web.config and in this case it is not presented anymore in the Metakeys collection.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    02 Dec 2010
    Link to this post
    Hi Ivan,

    No if i remove the code from the overridden method i do not get the error.

    My module only has three meta keys, and these havent changed. Its something to do with the databinding of the dropdownlist, why I can't get any more error information than I put on my post.

    It would be useful to know what key the error message is referring to.

    Any ideas?

    Thanks
    higgsy
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Dec 2010
    Link to this post
    Hello higgsy,

    Check the sitefinity.log file in App_Data. There could be some more details about the issue.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    09 Dec 2010
    Link to this post
    Hi Ivan,

    The sitefinity.log file shows the following:

    09/12/2010 11:31:11 [UNKNOWN]
    ************************************************************************************
    ID: 1bc013e6-3b17-4238-8aaf-5e28541a3ff8; Code: 3005; Occurrence: 4; Sequence: 39
    ------------------------------------------------------------------------------------

    Application information:
        Machine name: WIN-B74U7E9TRXT
        OS Version: Microsoft Windows NT 6.0.6002 Service Pack 2
        Product Version: 3.7.2096.2
        Application Path: D:\tnf\www\
        Debug: True

    Process information:
        Process ID: 2532
        Process Name: w3wp

    Request information:
        Request URL: /sitefinity/admin/Modules.aspx?module=Publications&route=PublicationsControlPanel.PublicationsView.PublicationsEditView&Param=e64f6db6-977d-48ba-b99f-8e5ff8affd03&ParentId=00000000-0000-0000-0000-000000000000
        Rewrite URL: http://www.tnf.local/sitefinity/admin/Modules.aspx?module=Publications&route=PublicationsControlPanel.PublicationsView.PublicationsEditView&Param=e64f6db6-977d-48ba-b99f-8e5ff8affd03&ParentId=00000000-0000-0000-0000-000000000000
        Url Referrer:    Is Authenticated: True
        Authentication Type: Forms
        User: admin
        User Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.215 Safari/534.10
        User Address: 127.0.0.1

    Variables:
        CmsHttpRequest: /sitefinity/admin/Modules.aspx?module=Publications&route=PublicationsControlPanel.PublicationsView.PublicationsEditView&Param=e64f6db6-977d-48ba-b99f-8e5ff8affd03&ParentId=00000000-0000-0000-0000-000000000000
        AspSessionIDManagerInitializeRequestCalled: True
        AspSession: System.Web.SessionState.HttpSessionState
        RadControlRandomNumber: 0

    - L0 -------------------------------------------------------------------------------

    Exception Type: System.Collections.Generic.KeyNotFoundException

    Message: The given key was not present in the dictionary.

    Source: mscorlib

    Stack Trace:
       at System.ThrowHelper.ThrowKeyNotFoundException()
       at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
       at Telerik.Cms.Engine.StagedContent.GetMetaData(String key)
       at Telerik.Cms.Engine.WebControls.ContentMetaFields.CreateChildControls()
       at System.Web.UI.Control.EnsureChildControls()
       at System.Web.UI.WebControls.CompositeControl.get_Controls()
       at Telerik.Framework.Web.ControlTraverser.GetBreadthFirst(Boolean isRecursionCall)
       at Telerik.Framework.Web.ControlTraverser.GetBreadthFirst(Boolean isRecursionCall)
       at Telerik.Framework.Web.ControlTraverser.MoveNext()
       at Telerik.Cms.Web.UI.GenericContainer.FindTypedControl(String id, Type searchType, TraverseMethod method)
       at Telerik.Cms.Web.UI.GenericContainer.GetControl[T](String id, Boolean required, TraverseMethod method)
       at Telerik.Cms.Engine.WebControls.Admin.ContentItemEdit`1.get_TagsControl()
       at Telerik.Cms.Engine.WebControls.Admin.ContentItemEdit`1.SetContentForm(IContent cnt)
       at App_Code.Modules.Publications.PublicationsModule.WebControls.Admin.PublicationsEditView.SetContentForm(IContent cnt) in d:\tnf\www\App_Code\Modules\Publications\WebControls\Admin\PublicationsEditView.cs:line 116
       at Telerik.Cms.Engine.WebControls.Admin.ContentItemEdit`1.InitializeControls(Control viewContainer)
       at App_Code.Modules.Publications.PublicationsModule.WebControls.Admin.PublicationsEditView.InitializeControls(Control viewContainer) in d:\tnf\www\App_Code\Modules\Publications\WebControls\Admin\PublicationsEditView.cs:line 75
       at Telerik.Cms.Web.UI.ViewModeControl`1.CreateChildControls()
       at App_Code.Modules.Publications.PublicationsModule.WebControls.Admin.PublicationsEditView.CreateChildControls() in d:\tnf\www\App_Code\Modules\Publications\WebControls\Admin\PublicationsEditView.cs:line 44
       at System.Web.UI.Control.EnsureChildControls()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    On my Modules Edit View, within SetContentForm I am trying the following:

    public class User {
     
                public string UserId { get; set; }
                public string FullName { get; set; }
     
            }
     
            protected override IContent SetContentForm(IContent cnt) {
     
                TnfDataAccess.DAL db = new TnfDataAccess.DAL();
                var sql = from u in db.Telerik_Users
                          let FirstName = (from fname in db.Telerik_UserMetaInfo
                                           where fname.UserId == u.UserId
                                           && fname.PropertyName == "FirstName"
                                           select fname.Text).SingleOrDefault()
                          let LastName = (from fname in db.Telerik_UserMetaInfo
                                          where fname.UserId == u.UserId
                                          && fname.PropertyName == "LastName"
                                          select fname.Text).SingleOrDefault()
                          join uir in db.Telerik_UsersInRoles on u.UserId equals uir.UserId
                          join r in db.Telerik_Roles on uir.RoleId equals r.RoleId
                          where r.LoweredRoleName == "members"
                          select new User { UserId = u.UserId.ToString(), FullName = String.Concat(FirstName, " ", LastName) };
     
                //loop through rows in linq query
                foreach (User oUser in sql) {
     
                    this.oUserDropDownList.Items.Add(new ListItem(oUser.FullName, oUser.UserId));
     
                }
     
                this.oUserDropDownList.DataSource = sql;
                this.oUserDropDownList.DataTextField = "FullName";
                this.oUserDropDownList.DataValueField = "UserId";
                this.oUserDropDownList.DataBind();
     
                return base.SetContentForm(cnt);
     
            }

    The metakeys for this module are:

    <add key="PublicationsModule.Name" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="" />
                    <add key="PublicationsModule.UserID" valueType="ShortText" visible="True" searchable="False" sortable="True" defaultValue="0" />
                    <add key="PublicationsModule.PublicationFrequency" valueType="ShortText" visible="True" searchable="False" sortable="True" defaultValue="0" />

    Based on the error message given, it looks as if SiteFinity is trying to find the metadata for the keys FullName, which doesnt exist - its just used as part of the linq query.

    In fact, even when I remove all the code from setcontentform and just replace it with the following, I get the same error:

    this.oUserDropDownList.Items.Add(new ListItem("text", "value"));
     
    return base.SetContentForm(cnt);

    Can you please help, it's very frustrating because I have no way of finding out any further information.

    Regards,
    higgsy
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Dec 2010
    Link to this post
    Hi higgsy,

    The error is thrown right after GetMetaData method is called and you get KeyNotFoundException()

    It look like you are trying to use a metakey that does not exist in your web.config or database.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
6 posts, 0 answered