How to run a 32bit dotnet 6 console application in Ubantu machine

83 views Asked by At

currently I have created a .net console App using dotnet new console -n HelloWorld. if I try to build it using dotnet build and run using dotnet run I am able to see the output . and the .csproj of this 64bit App is like this.

<Project Sdk="Microsoft.NET.Sdk">
 <PropertyGroup>
  <OutputType>Exe</OutputType>
  <TargetFramework>net6.0</TargetFramework>
  <ImplicitUsings>enable</ImplicitUsings>
  <Nullable>enable</Nullable>
 </PropertyGroup>
</Project>

But if I try to run this as a 32bit App by adding <PlatformTarget>x86</PlatformTarget>

<Project Sdk="Microsoft.NET.Sdk">
 <PropertyGroup>
  <OutputType>Exe</OutputType>
  <TargetFramework>net6.0</TargetFramework>
  <ImplicitUsings>enable</ImplicitUsings>
  <PlatformTarget>x86</PlatformTarget>
 </PropertyGroup>
</Project>
 

then if I try to build this application by using dotnet build I am able to build but if I try to run by using dotnet run it gives me the error as

Unhandled exception. System.BadImageFormatException: Could not load file or assembly 
'/home/simu_linux/Test/HelloWorld/bin/Debug/net6.0/HelloWorld.dll'. An attempt was made
 to load a program with an incorrect format. File name: 
'/home/simu_linux/Test/HelloWorld/bin/Debug/net6.0/HelloWorld.dll'

 

then I tried couple of way to solve this I tried to run directly from bin folder dotnet <myapp>.dll this also gave the same error . I tried by using dotnet run -c Debug -r linux-x86 I got the below error enter image description here

I tried with mono I was able to run this 32bit by using mono <myapp>.dll but If I keep any System.IO logic. enter image description here

and then If use mono <myapp>.dll then I facing issue enter image description here I guess I have to use this command

dotnet run -c Debug -r linux-x86

but since linux-86 RID is not there in my ubantu How can I solve this issue. since all my libraries are in 32 bit so I need a executable in 32 bit , I can not migrate it to 64 bit. So Can any please tell me how can I generate a custom 32bit dotnet for linux(ubantu).

0

There are 0 answers