Fluentmigrator: Failure to load referenced assembly when using dotnet-fm

Created on 31 Jul 2018  路  3Comments  路  Source: fluentmigrator/fluentmigrator

In my project, during migration, I want to do some custom SQL work, so I'm referencing Dapper and Dapper.Contrib. When running the migrations however, using dotnet-fm, I get the following error:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Dapper.Contrib, Version=1.50.5.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

This only happens when running it using dotnet-fm. If I write my own custom tool and migrate from code:

        var runner = serviceProvider.GetRequiredService<IMigrationRunner>();
        runner.MigrateUp();

It works just fine. Any ideas?

by-design question dotnet-fm

All 3 comments

The problem is, that the dotnet-fm tool doesn't know where to find Dapper.Contrib. There are currently three solutions:

  • Only run dotnet-fm after publishing the program/library
  • Ensure that all migrations are in a separate assembly that doesn't reference other packages (like Dapper.Contrib)
  • Avoid dotnet fm and use the in-process migrator (as you already did)

Just to clarify: The dotnet fm tool operates on an assembly and not on a project. You'd be required to process all references (project references, package references and direct assembly references) and that would be a huge amount of work.

@fubar-coder Thanks for the follow up, and thanks for an awesome library.

Was this page helpful?
0 / 5 - 0 ratings