EntityFramework.Docs
EntityFramework.Docs copied to clipboard
Document tooling workaround for projects targeting x86
File a bug
When setting a WinForms project with <PlatformTarget>x86</PlatformTarget> I cannot add a migration because of the following error: Could not load assembly 'EFCorex86MigrationFail'. Ensure it is referenced by the startup project 'EFCorex86MigrationFail'.. That happens when Context is in the startup project. When having a solution where Context is in a separate project, this error happens: System.IO.FileNotFoundException: Could not load file or assembly 'EFCorex86MigrationFail, Culture=neutral, PublicKeyToken=null'.
Include your code
Reproduction: https://github.com/twojnarowski/EFCorex86MigrationFail
Steps: Create WinForms app on .NET8, add 3 EF Core nugets - Design, Tools and SQLServer. Create a Context class. Run add-migration command - everything works. Change project settings to target platform x86, run add-migration, migration fails.
Include verbose output
Issue when Context in Startup Project:
PM> add-migration InitialMigration
Build started...
Build succeeded.
Could not load assembly 'EFCorex86MigrationFail'. Ensure it is referenced by the startup project 'EFCorex86MigrationFail'.
Issue when Context in a separate project:
PM> add-migration InitialMigration -context EFContext
Build started...
Build succeeded.
System.IO.FileNotFoundException: Could not load file or assembly 'EFCorex86MigrationFail, Culture=neutral, PublicKeyToken=null'. Nie można odnaleźć określonego pliku.
File name: 'EFCorex86MigrationFail, Culture=neutral, PublicKeyToken=null'
at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.get_StartupAssembly()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.get_MigrationsOperations()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Could not load file or assembly 'EFCorex86MigrationFail, Culture=neutral, PublicKeyToken=null'. Nie można odnaleźć określonego pliku.
Include provider and version information
EF Core version: 8.0.11 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: NET 8.0 Operating system: Windows 11 IDE: Visual Studio 2022 17.4
Workaround:
Set project back to Any CPU, create migration, update database. Return project back to x86, everything works.