Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7831917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:56:24+00:00 2026-06-02T11:56:24+00:00

I have a custom module. Migrations.cs looks like this. public int Create() { SchemaBuilder.CreateTable(MyModuleRecord,

  • 0

I have a custom module. Migrations.cs looks like this.

    public int Create()
    {
        SchemaBuilder.CreateTable("MyModuleRecord", table => table
            .ContentPartRecord()
            ...
        );

        ContentDefinitionManager.AlterPartDefinition(
            typeof(MyModulePart).Name, cfg => cfg.Attachable());

        ContentDefinitionManager.AlterTypeDefinition("MyModule",
           cfg => cfg
                .WithPart("MyModulePart")
                .WithPart("CommonPart")
                .Creatable()
            );

        return 1;
    }

This is the code I have in the controller.

  var newcontent = _orchardServices.ContentManager.New<MyModulePart>("MyModule");
  ...
  _orchardServices.ContentManager.Create(newcontent);

I get the invalid cast error from this New method in Orchard.ContentManagement ContentCreateExtensions.

    public static T New<T>(this IContentManager manager, string contentType) where T : class, IContent {
        var contentItem = manager.New(contentType);
        if (contentItem == null)
            return null;

        var part = contentItem.Get<T>();
        if (part == null)
            throw new InvalidCastException();

        return part;
    }

Any idea what I am doing wrong?

Thanks.

This is the handler.

public class MyModuleHandler : ContentHandler
{
    public MyModuleHandler(IRepository<MyModuleRecord> repository)
    {
        Filters.Add(StorageFilter.For(repository));
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T11:56:30+00:00Added an answer on June 2, 2026 at 11:56 am

    You are getting the InvalidCastException because the content item doesn’t appear to have your MyModulePart attached.

    If there were a driver for your part, then there is an implicit link somewhere that allows your part to be shown on a content item (I’m not sure how this is done, maybe someone else could elaborate – but it is something to do with how shapes are harvested and picked up by the shape table deep down in Orchard’s core).

    However since you don’t have a driver, adding an ActivatingFilter to your part’s handler class will make the link explicitly:

    public MyModulePartHandler : ContentHandler {
        public MyModulePartHandler() {
            Filters.Add(StorageFilter.For(repository));
            Filters.Add(new ActivatingFilter<MyModulePart>("MyModule");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a custom module for Orchard following this wonderful guide . I have
I have a custom Drupal module displaying some data in a table. Each row
I have created a custom module and am using hook_block to programmatically create some
I have a custom HTTP Module. I would like to inject the logger using
I have created a custom module that creates a custom Database table. I have
I have installed a schema for a custom module which creates the table when
I have a module like this: module Controller module LocaleModels def self.included(base) base.send :include,
i have a custom module with a form I have implemented form hooks like
I have a custom module I made for Magento. From the admin, there is
I have a custom module I made to show featured products on the homepage.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.