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 ?
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)
{
}
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)
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:
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 ?
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.
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.
you just need to change protected to public.
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
That makes sense, it explains the reflection error, thanks mate
I am still having this issue, even though my constructor of my class is public.
The entry is written into the migration db table, but the error in the log is:
System.MissingMethodException: No parameterless constructor defined for this object. at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) at Umbraco.Core.Persistence.Migrations.MigrationResolver.MigrationServiceProvider.GetService(Type serviceType) at Umbraco.Core.ServiceProviderExtensions.CreateInstances[T](IServiceProvider serviceProvider, IEnumerable`1 types, ILogger logger, Boolean throwException)
is working on a reply...