Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Giu 16 posts 122 karma points
    Jan 04, 2018 @ 13:24
    Giu
    0

    Umbraco Migration process: Error with MigrationBase class

    Hi, I am using the 7.7.7 version and I wanted to add columns for one of my custom tables in my Umbraco project. As I did that before in 7.6.8, I copy the code I have:

     public class TestFeatureMigration : MigrationBase
    {
        public TestFeatureMigration (ISqlSyntaxProvider sqlSyntax, ILogger logger) : base(sqlSyntax, logger)
        {
    
        }
    
        public override void Down()
        {
            Delete.FromTable("table1").Row("row1");
        }
    
        public override void Up()
        {
            Alter.Table("table1").AddColumn("row1").AsInt32().Nullable();
        }
    }
    

    And when I call this class using an ApplicationEventHandler, I get this weird exception:

    Logger: Umbraco.Core.PluginManager

    Error creating type TestFeatureMigration System.MissingMethodException: No parameterless constructor defined for this object.

    So it's a reflection issue and umbraco is expecting an empty constructor for TestFeatureMigration. The problem is that MigrationBase is requesting a constructor with those parameters.

    Is it a breaking change between 7.6 and 7.7 ? Am I using MigrationBase wrong ?

  • Giu 16 posts 122 karma points
    Feb 01, 2018 @ 16:04
    Giu
    0

    I found the issue, it looks like it's not possible to have 2 classes inheriting from MigrationBase at the same time in the same project.

  • Kevin Jump 1521 posts 9749 karma points MVP 3x c-trib
    Feb 01, 2018 @ 17:03
    Kevin Jump
    101

    Hi,

    you can have multiple classes inheriting from migration base, it was probibly more likely that the default constructor when you overrode the class was protected.

    this catches me out all the time :( when you inherit the class in visual studio the default constructor will be protected.

      public class Testmigration : MigrationBase
        {
            protected Testmigration(ISqlSyntaxProvider sqlSyntax, ILogger logger) : base(sqlSyntax, logger)
            {
            }
    

    you just need to change protected to public.

  • Lee Kelleher 3884 posts 14615 karma points MVP 9x admin c-trib
    Feb 22, 2018 @ 18:34
    Lee Kelleher
    0

    Thank you Kevin! I've been scratching my head for the past few hours trying to figure out what was going wrong... and yup, the constructor was protected! (facepalm)

    Cheers,
    - Lee

  • Giu 16 posts 122 karma points
    Feb 01, 2018 @ 17:21
    Giu
    0

    That makes sense, it explains the reflection error, thanks mate

Please Sign in or register to post replies

Write your reply to:

Draft