Importing Problem

Topics: Troubleshooting
Sep 2, 2011 at 3:11 PM

I'm trying to create a recipe for setting up a site which is using the Advanced Menu module. The module does not yet have the import/export overrides in the drivers, so I added them to my local copy. This is something I've done before with no problem - they're pretty straight forward.

However when I try to run the recipe on setting up a new site, it bombs with an exception from Nhibernate that the MenuName column can't be null (from the AdvancedMenuItemPartDriver). However I'm definitely mapping the value over to the part, and the part has the value in the XML. Here's what the data element looks like from my recipe XML:

    <SimpleMenuItem Id="/Identifier=05cfd800dd5742dea80cc0adb8e20d0d" Status="Published">
      <IdentityPart Identifier="05cfd800dd5742dea80cc0adb8e20d0d" />
      <CommonPart Owner="/User.UserName=admin" CreatedUtc="2011-09-01T18:59:52Z" PublishedUtc="2011-09-01T18:59:52Z" ModifiedUtc="2011-09-01T18:59:52Z" />
      <AdvancedMenuItemPart Text="About Us" Position="1" Url="~/about" MenuName="TopMenu" DisplayText="true" DisplayHref="true" />

You can see the MenuName attribute is on the AdvancedMenuItemPart node. I tried adding an ILogger to the driver and logging some messages in the importing method to see what's going on, but they don't log anything (even using Error or Fatal). So then I tried running it in debug and setting a breakpoint in the importing method, but it never hits the breakpoint.

Anyone have ideas on what could be wrong, or why I can't log or debug the importing method?

Sep 2, 2011 at 8:58 PM

Can you show how you wired up the import?

Sep 2, 2011 at 9:24 PM

Sure, here it is:

protected override void Importing(AdvancedMenuItemPart part, ImportContentContext context) {
    string partName = part.PartDefinition.Name;

    part.Text = GetAttribute<string>(context, partName, "Text");
    part.Position = GetAttribute<string>(context, partName, "Position");
    part.Url = GetAttribute<string>(context, partName, "Url");
    part.MenuName = GetAttribute<string>(context, partName, "MenuName");
    part.SubTitle = GetAttribute<string>(context, partName, "SubTitle");
    part.Classes = GetAttribute<string>(context, partName, "Classes");
    part.DisplayText = GetAttribute<bool>(context, partName, "DisplayText");
    part.DisplayHref = GetAttribute<bool>(context, partName, "DisplayHref");

//Using TV for generic parameter here simply to avoid confusion with T Localizer property
private TV GetAttribute<TV>(ImportContentContext context, string partName, string elementName) {
    string value = context.Attribute(partName, elementName);
    if (value != null) {
        return (TV)Convert.ChangeType(value, typeof(TV));
    return default(TV);

That GetAttribute helper method is the same one I included in my pull request for Vandelay.Industries. On a side note, I'm interested in what people think about that method and whether they'd like to see something like that (maybe not that code exactly - if anyone has suggestions for improvements let me know) in the core framework to make writing the import code easier.

Anyway, I tried removing that helper from the equation by just inlining the context.Attribute call but I got the same result, so it's not that (plus I've successfully used it elsewhere).

Sep 2, 2011 at 10:27 PM

Did you add that to the existing driver or did you create a new one?

Sep 3, 2011 at 1:57 AM

I added it to the existing driver.

Sep 3, 2011 at 1:58 AM

Weird. You might want to debug above that, right in the import logic, to see why your override is not being called.