Describe the bug
Attempting to run 'dotnet fm migrate' on a migration fails with the following exception, if I use a certain option in the migration:
dotnet fm migrate -c "..." -p sqlserver -a Schema.dll
-------------------------------------------------------------------------------
xxx: xxx migrating
-------------------------------------------------------------------------------
Beginning Transaction
Rolling back transaction
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
at xxx.Schema.xxx.Up()
at FluentMigrator.MigrationBase.GetUpExpressions(IMigrationContext context) in d:\a\1\s\src\FluentMigrator\MigrationBase.cs:line 83
at FluentMigrator.Runner.MigrationRunner.ExecuteMigration(IMigration migration, Action`2 getExpressions) in d:\a\1\s\src\FluentMigrator.Runner\MigrationRunner.cs:line 831
at FluentMigrator.Runner.MigrationRunner.ApplyMigrationUp(IMigrationInfo migrationInfo, Boolean useTransaction) in d:\a\1\s\src\FluentMigrator.Runner\MigrationRunner.cs:line 607
at FluentMigrator.Runner.MigrationRunner.MigrateUp(Int64 targetVersion, Boolean useAutomaticTransactionManagement) in d:\a\1\s\src\FluentMigrator.Runner\MigrationRunner.cs:line 427
at FluentMigrator.Runner.Initialization.TaskExecutor.Execute() in d:\a\1\s\src\FluentMigrator.Runner\Initialization\TaskExecutor.cs:line 165
at FluentMigrator.DotNet.Cli.Commands.BaseCommand.ExecuteMigrations(MigratorOptions options, IConsole console) in d:\a\1\s\src\FluentMigrator.DotNet.Cli\Commands\BaseCommand.cs:line 32
at FluentMigrator.DotNet.Cli.Commands.Migrate.OnExecute(IConsole console) in d:\a\1\s\src\FluentMigrator.DotNet.Cli\Commands\Migrate.cs:line 35
--- End of stack trace from previous location where exception was thrown ---
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.Invoke(MethodInfo method, Object instance, Object[] arguments)
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context)
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<<Apply>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass142_0.<OnExecute>b__0()
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](CommandLineContext context)
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](IConsole console, String[] args)
at FluentMigrator.DotNet.Cli.Program.Main(String[] args) in d:\a\1\s\src\FluentMigrator.DotNet.Cli\Program.cs:line 35
This is my migration:
public override void Up()
{
Alter.Table("MyTable")
.AddColumn("MyColumn").AsBoolean().SetExistingRowsTo(false);
}
If I remove SetExistingRowsTo it succeeds. If I try SetDefaultValueTo the error is also present.
To Reproduce
Expected behavior
No error to occur, the migration should succeed.
Information (please complete the following information):
fluentmigrator.dotnet.cli 3.2.6) and FluentMigrator 3.2.6 used by the schema projectAdditional context
I've seen a similar report at https://github.com/fluentmigrator/fluentmigrator/issues/1188 but it was unclear what the resolution is. It's also interesting the migration fails when using some optional extension methods (eg SetExistingRowsTo) but otherwise works fine.
I have tried adding System.Runtime to my project via nuget but it did not resolve the error.
@Plasma This is why I created https://github.com/fluentmigrator/fluentmigrator/issues/1178 , which is very close to merge-ready. A workaround is to use an In-Process Runner. I also created #1208 so that when people HAVE to use an In-Process Runner in the future, they can do so in a maintainable way that doesn't cause them to effectively fork FluentMigrator.DotNet.Cli code base or clumsily copy-paste stuff they think they need "now" without anticipating future needs.
In the mean time (I was hoping to wrap up 3.3 this past weekend but I spilled tea on my keyboard and am waiting on Amazon to deliver a new one), you MIGHT get your migrations to run if you use the develop branch package feed on AzureDevOps. This is the 4.0 branch and unofficial. 3.3.x will merge into 4.0 and we will likely focus exclusively on 4.0 once that merge happens. This is probably the biggest "bug" in FluentMigrator, in the sense most .NET developers have a hard time understanding why this error occurs, and I'm very close to fixing it and just focusing on features and feature parity across database processors.
Amazing @jzabroski thank you -- the reason we use the dotnet fm migrate tool is to perform migrations against production environment (not local dev, so in-process runner does not make sense here). Looking forward to the PR merge.
I mean, in-process runner can make sense - just squint for a second - if you have a private nuget package server like Proget, you can specify PackAsTool and ToolCommandName or whatever it's called and just pack it as a tool and then in your deployment download the nuget package and run it the same way you do FluentMigrator.Dotnet.Cli.
Agree if you're not pressed for workaround, best to wait as it wont be much longer. I've just had a string of bad luck during this lockdown and its hard to solve resource issues when everything is closed.
I just ran into this issue today, looking forward to the PR as well. Thank you @jzabroski
Just an update on this. I released 3.2.7 this morning. There is a small chance we will have a 3.2.8 release as there is an outstanding Oracle PR, but otherwise I am focused on finishing 3.3.0 which should address this problem.
Looking forward to this as well. Been seeing this issue in our project for a month or so.
Is there anyway to use the in process in a blank project to generate SQL scripts? That's my goal, but not finding a way to get it to work.
Hi, encountering the same issue "could not load file or assembly" System.Runtime for .Net 5.
Fluent Migrator works perfectly via application startup but failed using 'dotnet fm migrate'
@chuaxiangjie Currently, you must publish the project with the migrations and use the published DLL. It doesn't work when you use the DLL from the build output directory.
@fubar-coder This is a .NET 5 issue. @chuaxiangjie we currently don't handle .NET 5. You can workaround it by creating a DirtyAssemblyResolveHelper that rebinds various common assemblies.
That said, you really don't need .NET 5 to run FluentMigrator. Support for that will be coming soon, but I want to emphasize for most users its not even necessary.
As an update, 3.2.15 release contains a workaround for this problem via the allowDirtyAssemblies flag.
Most helpful comment
Just an update on this. I released 3.2.7 this morning. There is a small chance we will have a 3.2.8 release as there is an outstanding Oracle PR, but otherwise I am focused on finishing 3.3.0 which should address this problem.