Skip to content

Misleading error message when referenced assembly is built for different CPU architecture than project #101271

Open
@XVincentX

Description

@XVincentX

Description

If you are running an application in an architecture, say arm64 and you are referencing an assembly for a different architecture, say x64 - the error message that appears is misleading:

Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'src, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Problem is, the file is definitely there. What is happening is an architecture mismatch - not the file not being present on the disk.

Reproduction Steps

  1. Create a project for an architecture that is not compatible with your current computer. In my case I have a M3 MacBook, so x86 and x64 would not work:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <PlatformTarget>x86</PlatformTarget>
    <Nullable>enable</Nullable>
  </PropertyGroup>
</Project>
  1. Run the project:
dotnet run

Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'src, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
  1. Yet, the assembly is there:
ls bin/Debug/net8.0/ | grep src                                                                         (master)test
src
src.deps.json
src.dll
src.pdb
src.runtimeconfig.json

Expected behavior

The message should clearly say that there is an architecture mismatch for the assembly

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions