dotnet / dotnet/efcore

Specifying MigrationsAssembly with partial name fails to load proper assembly when assembly is not referenced

Open
#28,902 0 comments 0 reactions 0 assignees View on GitHub
area-migrations customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

Not sure if this is a bug or the documentation is behind. Following '[Using a Separate Migrations Project](https://docs.microsoft.com/en-gb/ef/core/managing-schemas/migrations/projects?tabs=vs)' I've created a separate migration assembly that's NOT referenced in the calling application, the migration assembly is copied over to the executing assembly's bin dir via BaseOutputPath and can be used normally when using a fully qualified assembly name. If using a short name as is given in the example, a file not found exception is thrown.

The example works fine if the assembly is referenced in the executing assembly, but that kinda defeats the purpose.

### Code

```
// throws in Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsAssembly on line 57
// works as expected if migration project is referenced in the executing project
optionBuilder.UseSqlServer(connectionString1,
x => x.MigrationsAssembly("Migrations.DB1"));
```

```
// works as expected in both cases
optionBuilder.UseSqlServer(connectionString1,
x => x.MigrationsAssembly("Migrations.DB1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"));
```

### Stack Trace

```
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'Migrations.DB1, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Source=
StackTrace:

```

EF Core version: 6.0.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6
Operating system: Win 10 21H2
IDE: VS 2022 17.3.2

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.