This project is read-only.

Not all Parts are being loaded for my Content Type

Topics: Troubleshooting, Writing modules
Jul 24, 2013 at 5:33 PM
We're still in the middle of migrating our largish code base from Orchard 1.3.9 to 1.6.1 and I'm currently facing the problem that our content items of type Entry are not loaded with all parts attached. I've generated some debug output that gives me this:

Parts defined for Entry Content Type:
CommonPart, EntryPart, LocalizationPart, PublishLater, AutoroutePart, TitlePart, ContentPermissionsPart
Loaded Entry instance's Parts:
GalleryPart, CountryPart, InfosetPart

Due to this our log file is full of errors complaining about the missing AutoroutePart on our content items.

The weird thing is that this started happening after I added a dependency to Orchard.Autoroute to our 'core' module's description in module.txt, which is also referenced by the module defining the EntryPart.

Any hints on why parts are not being loaded and how to investigate/debug this problem further?
Jul 24, 2013 at 6:26 PM
Edited Jul 24, 2013 at 6:27 PM
Investigating this problem further, I debugged into the creation of my Entry instance and found that DefaultContentManager.New() is being called:
public virtual ContentItem New(string type) {
    var typeDefinition = _contentDefinitionManager.GetTypeDefinition(type);
    if (typeDefinition == null) {
        typeDefinition = new ContentTypeDefinitionBuilder().Named(type).Build();
    // ...
public ContentTypeDefinition GetTypeDefinition(string name) {
    return _cacheManager.Get(name ?? string.Empty, ctx => {
        return _typeDefinitionRepository.Fetch(x => x.Name == name)
... which returns null. This seems very weird!
Jul 24, 2013 at 6:49 PM
I found the problem and the solution. During debugging I found that I never hit my breakpoint set inside the GetTypeDefinition(string name) method above...

The problem was that I have a class NullContentDefinitionManager that implements IContentDefinitionManager which was being returned by Autofac instead of Orchard's default ContentDefinitionManager. As stated in my original post, this happened after declaring a dependency on Orchard.Autoroute, so I guess that way I changed the order of registration for those two implementations, and suddenly my own was being registered after Orchard's.

Since I need my NullContentDefinitionManager but don't need to resolve it via DI, I just put the OrchardSuppressDependencyAttribute on it:
namespace Teamaton.Discoverize.CodeGeneration {
    public class NullContentDefinitionManager : IContentDefinitionManager {
        // ...
Now, the ContentDefinitionManager is used and the type definition for my Entry type is correctly fetched from the DB.