Copied to clipboard

Flag this post as spam?

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


  • Rich 22 posts 41 karma points
    Jan 05, 2011 @ 17:33
    Rich
    0

    Document.MakeNew() Error in API - The given key was not present in the dictionary

    Using the API in a stand alone project, I'm attempting to create a new document.

    Document d = Document.MakeNew(selectedMember.CompanyName, memberDocType, User.GetUser(0), memberSearch.Id);

    Provides me with an exception:

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

    And a stack trace of:

       at System.ThrowHelper.ThrowKeyNotFoundException()
       at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
       at umbraco.cms.businesslogic.datatype.controls.Factory.GetNewObject(Guid DataEditorId)
       at umbraco.cms.businesslogic.datatype.controls.Factory.DataType(Guid DataTypeId)
       at umbraco.cms.businesslogic.datatype.DataTypeDefinition.get_DataType()
       at umbraco.cms.businesslogic.property.Property.MakeNew(PropertyType pt, Content c, Guid versionId)
       at umbraco.cms.businesslogic.Content.addProperty(PropertyType pt, Guid versionId)
       at umbraco.cms.businesslogic.Content.createNewVersion()
       at umbraco.cms.businesslogic.Content.CreateContent(ContentType ct)
       at umbraco.cms.businesslogic.web.Document.MakeNew(String Name, DocumentType dct, User u, Int32 ParentId)
       at CsvParse.CSVImport.membersImport() in E:\Inetpub\wwwroot\Integra\CSVImport\CSVImport.cs:line 480

     

    I am using a 4.5.2 install.

    I've debugged and all the parameters have expected values. I am totally stumped so if anyone has any ideas, please do speak up.

    Thanks in advance.

  • Rich 22 posts 41 karma points
    Jan 05, 2011 @ 17:35
    Rich
    0

    I forgot to mention that I am running this on .net 2, Win XP and IIS 5.1.

    Thanks.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 05, 2011 @ 21:51
    Kim Andersen
    0

    Hi Rich

    Could we maybe see some of your code than just the one line that gives the error? Just some of the earlier code like eg. what the selectedMember contains.

    /Kim A

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jan 05, 2011 @ 22:50
    Aaron Powell
    0

    You're probably missing a DLL for a DataType which is on the DocumentType.

    Ensure you have all the DLLs in your /bin folder

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 07, 2011 @ 23:24
    Kim Andersen
    0

    Hi Rich.

    You found a solution to your problem?

    /Kim A

  • Rich 22 posts 41 karma points
    Jan 10, 2011 @ 12:50
    Rich
    0

    Thanks for your responses guys, sorry for my late reply but I had to resolve some other issues urgently.

     

    @Kim

    DocumentType memberDocType = DocumentType.GetByAlias("Member");
                    DocumentType memberInfoDocType = DocumentType.GetByAlias("MemberSearch");
    
                    IEnumerable memberSearchDocs = Document.GetDocumentsOfDocumentType(memberInfoDocType.Id);
                    Document memberSearch = null;
    
                    foreach (Document dMs in memberSearchDocs)
                    {
                        if (dMs.IsTrashed == false)
                        {
                            memberSearch = dMs;
                        }
                    }
    
                    foreach (DataRow row in dt.Rows)
                    {
                        try
                        {
    
                            CsvParse.Types.Member selectedMember = new CsvParse.Types.Member(row);
                            Document memberDoc = getMemberByMemberCode(selectedMember.MemberCode, memberDocType);
    
                            if (memberDoc == null)
                            {
                                if (memberSearch != null)
                                {                                                                
                                    Document d = Document.MakeNew(selectedMember.CompanyName, memberDocType, User.GetUser(0), memberSearch.Id);                                
                                    memberDoc = d;
                                    Utils.CreateAlphaFolder(memberDoc);
                                }
                                else
                                {
                                    //Error can not find product parent node to create in
                                }
                            }
    
            ........ update properties, rinse, repeat

     

    Basically, create a node if the Member (this is a datatype, not an umbraco member) couldn't be found in the CMS and update the properties. Debugging shows that all the parameters of the MakeNew method are as expected, which leads me to believe the code is fine and....

    @slace... which dll would contain this data?

     

    Thanks

  • Rich 22 posts 41 karma points
    Jan 14, 2011 @ 13:50
    Rich
    0

    @slace, do you think you could give me some details about your theory with the dll's please?

    If anyone has _any_ suggestions for this I could really use the help.

    Thanks.

  • Dallas 132 posts 404 karma points
    Feb 17, 2011 @ 22:41
    Dallas
    0

    Hi Rich

    You mention that you are accessing the api from a standalone project which I take to mean you are not accessing the api from within an umbraco web site? You are using the app from a console app or service for example.

    If so, I had this exact problem today and was also getting this error when trying to use the api from a console app. I tracked the problem down to the api call expecting an internal umbraco collection to be initialized. Calling the api does not do this initialization and the collection was empty. It turns out that the api expects to be running from within a website, and along with missing initialization step, it also has dependencies on HttpContext. This thread discusses this.

    It appears that using the Umbraco WebServices is the solution. Umbraco has some built in WebServices that allow you to create documents. This is what I used. I also found the webservice a bit confusing to use, and couldn't find any substantial documentation. Here is an example  for creating a document which got me on the right track.

    I haven't tried it but apparently, it is quite easy to create your own webservices and you can then use the api.

    And finally, the webservice dll did is not included in the binary release of  4.5.2. You need to get the source, do a build and copy the webservice.dll to your umbraco bin directory.


Please Sign in or register to post replies

Write your reply to:

Draft