Custom block content provider giving KeyNotFoundException

Vote:
 

Hi,

We are trying to use custom contet providers to serve test content within our site (EiServer 7.5). We have a basic provider serving pages and now we want to create one to serve blocks.

I have mapped the block provider to a folder in the 'Blocks' media folder and it is being called when you navigate to the folder, however, we are getting the following error:

[KeyNotFoundException: The given key was not present in the dictionary.]

System.Collections.Generic.Dictionary`2.get_Item(TKey key) +14269699
EPiServer.Core.ContentProvider.GetScatteredContents(IEnumerable`1 contentLinks, ILanguageSelector selector) +693
EPiServer.Core.ContentProvider.LoadChildren(ContentReference contentLink, ILanguageSelector selector, Int32 startIndex, Int32 maxRows) +378
EPiServer.Core.DefaultContentLoader.GetChildren(ContentReference contentLink, ILanguageSelector selector, Int32 startIndex, Int32 maxRows) +1438
EPiServer.Core.DefaultContentLoader.GetChildren(ContentReference contentLink, ILanguageSelector selector) +98


We have overridden just the LoadContent and the LoadChildrenReferencesAndTypes methods, which is all we seamed to need to do for the page provider.

protected override IContent LoadContent(ContentReference contentLink, ILanguageSelector languageSelector)

{

    if (contentLink.ID == 200000)

    {

        var contentType = ContentTypeRepository.Load();

        var parent = _contentRepository.Get(new ContentReference(24397));



        var block = GetDefaultContent(parent, contentType.ID, new LanguageSelector("en"));



        ((IContent)block).Name = "Test Block";

        ((IContent)block).ContentLink = new ContentReference(200000, "testBlocks");

        var versionable = block as IVersionable;

        if (versionable != null) versionable.Status = VersionStatus.Published;

        return (IContent)block;

    }

    return null;

}



protected override IList LoadChildrenReferencesAndTypes(ContentReference contentLink, string languageID, out bool languageSpecific)

{

    languageSpecific = false;

    IList result = new List();

    if (contentLink.ID == 24397)

    {

        result.Add(new GetChildrenReferenceResult()

        {

            ContentLink = new ContentReference(200000),

            IsLeafNode = true,

            ModelType = typeof(ContentBlock)

        });

    }

    return result;

}

I have had a look in GetScatteredContents via dotPeek and it seams to be trying to using the dictionary to lookup an index number from a ContentReference. I have overridden LoadContents, which is called just before this code and one of the arguments looks like it is created at the same time, but this is populated as I would expect.

Any ideas?

Thanks

#139915
Oct 09, 2015 15:03
Vote:
 

Did you ever figure this out? Struggling with the exact same issue.

#144232
Feb 09, 2016 14:58
Vote:
 

Sorry, No. We gave up on that plan in the end.

#144378
Feb 11, 2016 17:51
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.