Copied to clipboard

Flag this post as spam?

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


  • Jonathan Roberts 409 posts 1063 karma points
    Feb 03, 2015 @ 18:18
    Jonathan Roberts
    0

    Filtering IContent

    Hi,

    I had a search working on my umbraco site where I was getting a load of events and filtering them but now it is throwing a weird error: The alias datatypes have not changed. Any ideas?

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

    Line 39:     Umbraco.Core.Services.IContentService cs = ApplicationContext.Current.Services.ContentService;
    Line 40:     IEnumerable itemList = Enumerable.Empty();
    Line 41:     itemList = cs.GetChildren(EventsParent).OrderByDescending(x => x.GetValue("simpleEventDateFrom"));
    Line 42:     String[] catlist = itemList.Select(I => Convert.ToString(I.GetValue("simpleEventCategory"))).ToArray();
    Line 43:    


    Source File: d:\inetpub\wwwroot\roundsquare-uat\httpdocs\Views\SimpleEvents.cshtml    Line: 41 

    Stack Trace: 

    [KeyNotFoundException: The given key was not present in the dictionary.]
       System.Collections.Generic.Dictionary`2.get_Item(TKey key) +14332239
       System.Collections.ObjectModel.KeyedCollection`2.get_Item(TKey key) +70
       Umbraco.Core.Models.ContentBase.GetValue(String propertyTypeAlias) +32
       ASP._Page_Views_SimpleEvents_cshtml.b__14(IContent x) in d:\inetpub\wwwroot\roundsquare-uat\httpdocs\Views\SimpleEvents.cshtml:41
       System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count) +148
       System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count) +38
       System.Linq.d__0.MoveNext() +338
       System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +165
       System.Linq.Buffer`1..ctor(IEnumerable`1 source) +488
       System.Linq.Enumerable.ToArray(IEnumerable`1 source) +103
       ASP._Page_Views_SimpleEvents_cshtml.Execute() in d:\inetpub\wwwroot\roundsquare-uat\httpdocs\Views\SimpleEvents.cshtml:42
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +125
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +181
       Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +140
       System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +380
       System.Web.Mvc.<>c__DisplayClass1a.b__17() +33
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +613
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +613
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +263
       System.Web.Mvc.Async.<>c__DisplayClass25.b__22(IAsyncResult asyncResult) +240
       System.Web.Mvc.<>c__DisplayClass1d.b__18(IAsyncResult asyncResult) +28
       System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +15
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
       System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +15
       System.Web.Mvc.<>c__DisplayClass8.b__3(IAsyncResult asyncResult) +42
       System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +15
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

    This is my code: where simpleEventDateFrom is my alias datatype

    var EventsParent = 1460;
    Umbraco.Core.Services.IContentService cs = ApplicationContext.Current.Services.ContentService;
    IEnumerable itemList = Enumerable.Empty();
    itemList = cs.GetChildren(EventsParent).OrderByDescending(x => x.GetValue("simpleEventDateFrom"));
  • Zac 223 posts 575 karma points
    Apr 21, 2015 @ 13:39
    Zac
    0

    Seeing this same issue all of a sudden out of the blue with Umbraco 7.2.4

    private void PublishedHandler_Published(IPublishingStrategy sender, PublishEventArgs<IContent> args)
    {
        var contentService = new ContentService();
        foreach (var node in args.PublishedEntities)
        {
             var someProperty = node.GetValue<string>("someAlias");
        }
    }
    

    Gives me an error:

    Message "The given key was not present in the dictionary."
       at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
       at System.Collections.ObjectModel.KeyedCollection`2.get_Item(TKey key)
       at Umbraco.Core.Models.ContentBase.GetValue[TPassType](String propertyTypeAlias)
    
  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    Apr 21, 2015 @ 17:14
    Alex Skrypnyk
    0

    Hi Zac,

    Did you try to use GetPropertyValue method?

  • Zac 223 posts 575 karma points
    Apr 22, 2015 @ 01:50
    Zac
    0

    Hi Alex,

    It was a silly question, and I realised as soon as I posted it.

    I just expected it not to throw an exception, is all (like IPublishedContent). It was fine as soon as I checked if the content node had that property.

    Cheers, Zac

Please Sign in or register to post replies

Write your reply to:

Draft