Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • BK 7 posts 27 karma points
    Apr 29, 2010 @ 17:34
    BK
    0

    Create a member problem

    Here is a code segment:

     

     

     

     

     

     

     

     

     

    ---------

     

    MemberType demoMemberType = new MemberType(1222);

    Member newMember = Member.MakeNew("John Smith", demoMemberType, new umbraco.BusinessLogic.User (0));

    newMember.Email =

    [email protected];

    newMember.Password =

    "password";

    newMember.LoginName =

    "jsmith";

    newMember.getProperty(

    "address").Value = "123 Main Street";

    newMember.getProperty("city").Value = "New York";

    newMember.Save();

    ---------

    As I step thru the code, it pulls the correct MemberType out (from the id), but on the Member.MakeNew line, it crashes with this error:

    "The given key was not present in the dictionary." 

    Anyone have any ideas or suggestions?  Thanks in advance!

     

     

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 29, 2010 @ 18:05
    Lee Kelleher
    0

    Hi BK,

    Bit of guess work here, as to me the error message doesn't look like it comes from the Member.MakeNew method ... my guess is to do with the User.

    Try moving the User to a new line?

    MemberType demoMemberType = new MemberType(1222);
    umbraco.BusinessLogic.User user = new umbraco.BusinessLogic.User(0);
    Member newMember = Member.MakeNew("John Smith", demoMemberType, user);

    See if that's the line that returns the error ... if it does, make sure you have a User with an ID of "0" (and it's not been disabled).

    Other than that the "The given key was not present in the dictionary." error message is usually from a Collection-based object; Hashtable, Dictionary, etc.  It's a case of figuring out which 'key' is being expected and why isn't it there? (maybe copy-n-paste the full exception?)

    Cheers, Lee.

  • BK 7 posts 27 karma points
    Apr 29, 2010 @ 18:18
    BK
    0

    I've mode the User line as suggested.  When stepping thru the code, that line works fine.  It still crashes on the Member.MakeNew line (which is line 67):

    {"The given key was not present in the dictionary."}
        [System.Collections.Generic.KeyNotFoundException]: {"The given key was not present in the dictionary."}
        Data: {System.Collections.ListDictionaryInternal}
        HelpLink: null
        InnerException: null
        Message: "The given key was not present in the dictionary."
        Source: "mscorlib"
        StackTrace: "   at System.ThrowHelper.ThrowKeyNotFoundException()\r\n   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)\r\n   at umbraco.cms.businesslogic.datatype.controls.Factory.GetNewObject(Guid DataEditorId) in d:\\TeamCity\\buildAgent\\work\\7380c184e9fcd3ea\\umbraco\\cms\\businesslogic\\datatype\\factory.cs:line 50\r\n   at umbraco.cms.businesslogic.datatype.controls.Factory.DataType(Guid DataTypeId) in d:\\TeamCity\\buildAgent\\work\\7380c184e9fcd3ea\\umbraco\\cms\\businesslogic\\datatype\\factory.cs:line 40\r\n   at umbraco.cms.businesslogic.datatype.DataTypeDefinition.get_DataType() in d:\\TeamCity\\buildAgent\\work\\7380c184e9fcd3ea\\umbraco\\cms\\businesslogic\\datatype\\DataType.cs:line 79\r\n   at umbraco.cms.businesslogic.property.Property.MakeNew(PropertyType pt, Content c, Guid versionId) in d:\\TeamCity\\buildAgent\\work\\7380c184e9fcd3ea\\umbraco\\cms\\businesslogic\\Property\\Property.cs:line 105\r\n   at umbraco.cms.businesslogic.Content.addProperty(PropertyType pt, Guid
    versionId) in d:\\TeamCity\\buildAgent\\work\\7380c184e9fcd3ea\\umbraco\\cms\\businesslogic\\Content.cs:line 276\r\n   at umbraco.cms.businesslogic.Content.createNewVersion() in d:\\TeamCity\\buildAgent\\work\\7380c184e9fcd3ea\\umbraco\\cms\\businesslogic\\Content.cs:line 340\r\n   at umbraco.cms.businesslogic.Content.CreateContent(ContentType ct) in d:\\TeamCity\\buildAgent\\work\\7380c184e9fcd3ea\\umbraco\\cms\\businesslogic\\Content.cs:line 308\r\n   at umbraco.cms.businesslogic.member.Member.MakeNew(String Name, String Email, MemberType mbt, User u) in d:\\TeamCity\\buildAgent\\work\\7380c184e9fcd3ea\\umbraco\\cms\\businesslogic\\member\\Member.cs:line 308\r\n   at umbraco.cms.businesslogic.member.Member.MakeNew(String Name, MemberType mbt, User u) in d:\\TeamCity\\buildAgent\\work\\7380c184e9fcd3ea\\umbraco\\cms\\businesslogic\\member\\Member.cs:line 267\r\n   at IPIcontrols.SearchBasedOnEmail.Continue_Click(Object sender, EventArgs e) in C:\\Documents and Settings\\IpiConsultant\\My Documents\\Visual Stu
    dio 2008\\Projects\\IPIcontrols\\IPIcontrols\\SearchBasedOnEmail.ascx.cs:line 67"
        TargetSite: {Void ThrowKeyNotFoundException()}

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 29, 2010 @ 18:55
    Lee Kelleher
    0

    Hi BK,

    OK, a long shot here... have you deleted a data-type that is still being used in your member-type?

    If so, I think you'll have a problem here... not 100% sure how you can revert it ... unless anyone else has a better suggestion? My advice would be to delete the member-type and re-create it.

    Good luck, Lee.

  • BK 7 posts 27 karma points
    Apr 29, 2010 @ 19:26
    BK
    0

    Hey Lee,

    That was it!  Thanks!

    I just added a new member-type (with no properties) and it worked.  So what does this mean exactly - Are one of my referenced properties possibly gone or deleted?  What can I do to make sure this doesn't happen again? I'm not the only one in my umbraco site doing testing .. :)

    BK

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 29, 2010 @ 19:54
    Lee Kelleher
    0

    Hi BK,

    Glad that you got it working!

    As a general rule of thumb, I don't delete any of the data-types unless I am 100% certain that they are not being used in a document/media/member type.  If other developers are working the same Umbraco install, then instruct them to NEVER delete a data-type - leave that job to the lead developer.

    There are things that you can put in place to prevent it happening, but it will require some custom code to hook into the event handlers for the data-types (i.e. "umbraco.cms.businesslogic.datatype.DataTypeDefinition.Deleting").

    As for your existing "broken" member-type, it's not gone, but because one of its data-types is missing, it wont display properly in the back-office UI (throwing YSoD!)  It is fixable in the database, but that's a job far beyond a forum post reply.  Best bet is to delete the member-type and recreate it (if you know what all the properties are/were).

    Cheers, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft