Exception calling "Start" with "1" argument(s): "The specified executable is not a valid application for this OS platform." with all ef core commands

Arman Espiar 1 Reputation point
2024-11-26T12:02:35.5866667+00:00

When I run one of the ef core commands, I encounter the following error:

Exception calling "Start" with "1" argument(s): "The specified executable is not a valid application for this OS platform." At line:1 char:1

For example:

PM> Update-Database -Context ContentServiceCommandDbContext Build started... Build succeeded. Update-Database : Exception calling "Start" with "1" argument(s): "The specified executable is not a valid application for this OS platform." At line:1 char:1

  • Update-Database -Context ContentServiceCommandDbContext
  •     + CategoryInfo          : NotSpecified: (:) [Update-Database], MethodInvocationException
        + FullyQualifiedErrorId : Win32Exception,Update-Database
    

or

PM> Add-Migration ChangeSomething -Context ContentServiceCommandDbContext Build started... Build succeeded. Add-Migration : Exception calling "Start" with "1" argument(s): "The specified executable is not a valid application for this OS platform." At line:1 char:1

  • Add-Migration ChangeSomething -Context ContentServiceCommandDbContext
  •     + CategoryInfo          : NotSpecified: (:) [Add-Migration], MethodInvocationException
        + FullyQualifiedErrorId : Win32Exception,Add-Migration
    

and so on ...

There is a problem and it has nothing to do with version 8 or 9 of EF Core.

Capture

As you can see in the image, there is also the dotnet environment variable.

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
764 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 68,311 Reputation points
    2024-11-26T17:00:21.11+00:00

    what is the target platform of the build? and does it match the environment you are running the migrate from.


  2. Hongrui Yu-MSFT 3,165 Reputation points Microsoft Vendor
    2024-11-27T09:58:33.98+00:00

    Hi,@Arman Espiar. Welcome to Microsoft Q&A. 

    Judging from the current situation, this seems to be related to your environment. You could try the following methods. Method 1 Configure environment variables correctly: In Visual Studio 2022, open Terminal (View->Terminal) and run the dotnet --version command. If the .Net version could be successfully output, the environment variable configuration is successful. Of course, you could also delete the dotnet file in C:\Program Files, then re-download dotnet and install it. By default, it will automatically configure the dotnet operating environment for you.

    Reinstall Entity Framework Core related packages: Find Entity Framework Core related packages in C:\Users\{UserName}\.nuget\packages, delete them, and re-download them through Nuget

    Method 2 Execute Code First commands in .Net Core CLI Run commands in Terminal(View->Terminal)

    dotnet ef migrations add ChangeSomething
    
    dotnet ef database update
    

    Related Documents: Migrations Overview - EF Core | Microsoft Learn


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.