I set up a basic C# console application in Visual Studio Code like so:
dotnet new console
dotnet restore
I then build like so:
dotnet build
Then run:
dotnet run
This all works as expected. If I change the platform target to x86
though, I get this error when I build and run the application again:
Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 'C:\temp\code\testx86_2\bin\Debug\netcoreapp2.0\testx86_2.dll'. An attempt was made to load a program with an incorrect format.
My files:
Program.cs:
using System;
namespace testx86_2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}
testx86_2.csproj before setting the platform target:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
</Project>
testx86_2.csproj after setting the platform target:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
</Project>
Versions:
Adding --runtime win-x86
to the run command should force the runtime to launch in 32-bit mode, even if using the the x64 version of dotnet cli.
The <PlatformTarget>x86</PlatformTarget>
isn't needed, adding the switch to the run command is enough to force x86 mode. I would remove the PlatformTarget, to allow you to change between x86 / x64 more easily.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With