You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With RC1 I had a migration with a dependency on its constructor:
publicpartialclassMigrationWithDependency:Migration{privatereadonlyIDependency<Foo>theDependency;publicMigrationWithDependency(IDependency<Foo>theDependency){this.theDependency=theDependency;}protectedoverridevoidUp(MigrationBuildermigrationBuilder){varsomething=this.theDependency.DoSomething();migrationBuilder.Sql($"UPDATE Foo SET Bar = '{something}'");}protectedoverridevoidDown(MigrationBuildermigrationBuilder){// irrelevant}}
The issue
When I try to run something like database update I am getting the following error pointing out that I don't have a parameterless constructor for this object:
~/ dotnet ef database update -c myContext
Project FooWebApp (.NETFramework,Version=v4.5.2) was previously compiled. Skipping compilation.
System.MissingMethodException: No parameterless constructor defined for this object.
em System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
em System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
em System.Activator.CreateInstance(Type type, Boolean nonPublic)
em System.Activator.CreateInstance(Type type)
em Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsAssembly.CreateMigration(TypeInfo migrationClass, String activeProvider)
em Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.<PopulateMigrations>b__14_4(KeyValuePair`2 p)
em System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
em System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
em System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
em Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.PopulateMigrations(IEnumerable`1 appliedMigrationEntries, String targetMigration, IReadOnlyList`1& migrationsToApply, IReadOnlyList`1& migrationsToRevert)
em Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.<GetMigrationCommandLists>d__13.MoveNext()
em Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
em Microsoft.EntityFrameworkCore.Design.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
em Microsoft.EntityFrameworkCore.Tools.Cli.DatabaseUpdateCommand.<>c__DisplayClass0_0.<Configure>b__0()
em Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
em Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
No parameterless constructor defined for this object.
Previously in the RC1 dependencies were loaded from Startup.cs. Was it changed now? How can I pass dependencies to my migration constructors?
Also It would be valuable to have the class name in question exposed on the exception message... Among more than 50 migrations it took a lot to figure out what was the problem.
We'd like some more info on the scenario you are trying to achieve here to help us better triage the request. This may be quite difficult for us to do as EF doesn't have access to the application service provider where you are presumably registering the service you want to inject, but we'll consider it if there is a compelling scenario.
Hello. I am migrating from RC1 to RTM.
Steps to reproduce
With RC1 I had a migration with a dependency on its constructor:
The issue
When I try to run something like
database update
I am getting the following error pointing out that I don't have a parameterless constructor for this object:Previously in the RC1 dependencies were loaded from Startup.cs. Was it changed now? How can I pass dependencies to my migration constructors?
Also It would be valuable to have the class name in question exposed on the exception message... Among more than 50 migrations it took a lot to figure out what was the problem.
Further technical details
".NETFramework,Version=v4.5.2"
"Microsoft.AspNetCore.Mvc": "1.0.0"
"Microsoft.EntityFrameworkCore": "1.0.0"
It is probably similar to what you did with contexts: #5312
The text was updated successfully, but these errors were encountered: