skip to Main Content

I have a C# console app written under net 6.0. And I ran it complied exe file (I complied it in Windows and upload whole published folder to Linux VM) using mono, and get following message:

file does not contain a valid CIL image.

I checked the other thread and re-install dotnet package. But it still does not work out.

Please provide some help. Thanks.

2

Answers


  1. Chosen as BEST ANSWER

    I finally found the answer:

    1. Mono is not compatible with .net 6 so far.
    2. The correct command line to run the code is:

    dotnet program.dll

    (exe file is not working here)

    Thanks for you guys' help.


  2. .NET 6 is not compatible with Mono, so if you want your .NET 6 console app to run on Linux, you should need to strictly follow the .NET Core/.NET 6 guides,

    Running a self-contained ASP.NET Core application on Ubuntu

    The "complied exe file" generated for a .NET 6 console app by dotnet publish, is strictly a native Windows executable (equivalent of .NET CLI executable) that contains no MSIL. That’s why when you force Mono runtime to load it "file does not contain a valid CIL image" is reported. Don’t check any other threads, as Mono is going away and not what you should resort to at this moment, https://halfblood.pro/the-end-of-mono/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search