Skip to content

Document tooling workaround for projects targeting x86 #4924

Closed

Description

@twojnarowski

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.

Activity

  1. m1nh101 commented on Dec 20, 2024

    @m1nh101

    Have you changed the default project in visual studio integrated console to the the project that include the context?

  2. ChrisJollyAU commented on Dec 20, 2024

    @ChrisJollyAU
    Contributor

    I've seen this before. Simply put this is expected behaviour.

    I am almost certain that the .Net SDK you have installed is the x64 version.

    The thing is when you do the migration, .Net (usually dotnet.exe) needs to load your project so that it can call into it for the migrations and the database connection. However since the SDK is x64 and your project is x86 there is a mismatch and your project fails to load.

    Obviously targeting x64 will work. Any CPU will work for whichever .Net you have (x64, x86 and possibly ARM).

    Is there a particular need to specifically use x86? If so, it would be better to have the x86 .Net SDK installed and used as default

  3. twojnarowski commented on Dec 20, 2024

    @twojnarowski
    Author

    Have you changed the default project in visual studio integrated console to the the project that include the context?

    @m1nh101 when running x64 everything works, so you can assume that I did that :)

    Is there a particular need to specifically use x86? If so, it would be better to have the x86 .Net SDK installed and used as default

    @ChrisJollyAU Yes, there is. I am referencing a dll API from this project and it only works in x86. But I haven't downloaded any specific .NET SDK apart from what VS Installer installed. I will try to download x86 SDK and try with it.

  4. cincuranet commented on Jan 7, 2025

    @cincuranet
    Contributor

    @AndriySvyryd the steps provided above reliably replicate it. Even with both x64 and x86 runtimes installed (on .NET/EF 9.0).

  5. ChrisJollyAU commented on Jan 7, 2025

    @ChrisJollyAU
    Contributor

    @cincuranet @AndriySvyryd

    I you are in Visual Studio you are going to need to point it at the x86 dotnet manually. VS won't automatically use the x86.

    Best way to test in the developer command line and specifically use the full path to the dotnet executable for the dotnet ef dbcontext scaffold command

    We had a discussion on this exact topic on EFCore.Jet CirrusRedOrg/EntityFrameworkCore.Jet#95

  6. cincuranet commented on Jan 7, 2025

    @cincuranet
    Contributor

    But the report above is using PMC, not dotnet.exe directly.

  7. ChrisJollyAU commented on Jan 7, 2025

    @ChrisJollyAU
    Contributor

    But the report above is using PMC, not dotnet.exe directly.

    True. But PMC is going to use x64 unless you change PATH to point to the x86 dotnet

  8. cincuranet commented on Jan 7, 2025

    @cincuranet
    Contributor

    True. But PMC is going to use x64 unless you change PATH to point to the x86 dotnet

    @AndriySvyryd is this something we want to deal with out of the box? Or at least document?

  9. AndriySvyryd commented on Jan 8, 2025

    @AndriySvyryd
    Member

    @AndriySvyryd is this something we want to deal with out of the box? Or at least document?

    It would be very risky to try to manipulate PATH ourselves. We'll document.

  10. transferred this issue fromdotnet/efcoreon Jan 8, 2025
  11. changed the title [-]Could not load assembly 'Name'. Ensure it is referenced by the startup project 'Name'[/-] [+]Document tooling workaround for projects targeting x86[/+] on Jan 8, 2025
  12. added this to the Backlog milestone on Jan 8, 2025
  13. ChrisJollyAU commented on Jan 8, 2025

    @ChrisJollyAU
    Contributor

    @AndriySvyryd Probably best solution overall, would be in the global.json file to add a line to specify x86 or x64
    e.g.
    "architecture": "x86",

    Edit: this won't work currently and is a suggestion for a feature

  14. added a commit that references this issue on Aug 11, 2026
    bb42937
  15. modified the milestones: Backlog, 11.0.0 on Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions