Error Creating a Content Part

Topics: Troubleshooting, Writing modules
Mar 4, 2011 at 5:30 AM

I followed the "Writing a Content Part" documentation (http://orchardproject.net/docs/Writing-a-content-part.ashx) and I can't get the Create method in the Migrations class to be called.  Thus, my custom table is never created.  What do I need to do for Create() to be called in the Migrations class?  Also, I'm now getting the same error a lot of other people seem to be getting after creating this part when I try to edit content types.  The infamous stack trace is below.

at Autofac.Util.Enforce.ArgumentNotNull[T](T value, String name) at Autofac.Core.KeyedService..ctor(Object serviceKey, Type serviceType) at Orchard.Mvc.OrchardControllerFactory.TryResolve[T](WorkContext workContext, Object serviceKey, T& instance) at Orchard.Mvc.OrchardControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.b__2() at System.Web.Mvc.SecurityUtil.<>c__DisplayClassb`1.b__a() at System.Web.Mvc.SecurityUtil.b__0(Action f) at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust[TResult](Func`1 func) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) at Orchard.Mvc.Routes.ShellRoute.HttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

 

I can only assume these two issues are related.  I tried the idea posted by Bertrand to alter the Layout.cshtml file in the admin theme, but that doesn't seem to help.  Any ideas? Thanks!

Mar 4, 2011 at 4:41 PM

Create will not run twice without the database being reset in between. So it might be that you ran the migration once before it was ready and now it's not running it again.

This is because the version returned by create is stored in the table Orchard_Framework_DataMigrationRecord.

While developing a module and you're messing around with your migration, you can either reset the database in between tests or use the UpdateFrom methods to try new things and then consolidate these in the Create method when you're done.

If you were currently at migration version 1 you would add an UpdateFrom1() method like this:

public int UpdateFrom1
{
   // Do something
   return 2;
}

After this we are now at migration version 2 and subsequently you would use the UpdateFrom2() method.

I prefer to reset the database and take a backup just before I start messing with migration files so I can easilly roll back.

Hope that helps,

Richard.

Mar 5, 2011 at 3:13 AM

Thanks for the reply, Richard.  After querying to see what was stored in Orchard_Framework_DataMigrationRecord, I noticed that my Migrations class is not in there which would seem to indicate the Create method has never been called.  Do you know how this is possible?

Mar 5, 2011 at 12:16 PM

That does seem to suggest your migration is not running at all.

I can't think of anything obvious that could be wrong. Could you post your full DataMigration class here, so people can see if they can see anything wrong with it.

Still might be worth zapping your database too, just in case there is some junk in there.