Hot Reload with a specific code structure throws `System.BadImageFormatException: An attempt was made to load a program with an incorrect format.`
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
### Description
Using `dotnet watch` on a project and modifying the code of a class with a very specific structure fails as follows:
```
value: 3
value: 3
value: 3
dotnet watch ⌚ File changed: ./osu.Game/Overlays/Profile/Header/Components/Faulty.cs.
value: 3
dotnet watch 🔥 Hot reload of changes succeeded.
Unhandled exception. System.BadImageFormatException: An attempt was made to load a program with an incorrect format.
(0x8007000B)
at osu.Game.Overlays.Profile.Faulty.<>c.b__0_0(Model s)
at osu.Game.Overlays.Profile.Faulty.Method()
at Program.$(String[] args) in /Users/salman/Projects/osu/ExecutableProject/Program.cs:line 9
dotnet watch ❌ Exited with error code 134
dotnet watch ⏳ Waiting for a file to change before restarting dotnet...
```
### Reproduction Steps
I have tried to isolate this as much as I could, and this is the best I have gotten.
1. Check out this branch: https://github.com/ppy/osu/compare/master...frenzibyte:osu:breaking-hot-reload
2. Run `ExecutableProject` located at the root folder of the repository with `dotnet watch`
3. Modify line 15 of the file `osu.Game/Overlays/Profile/Header/Components/Faulty.cs`
### Expected behavior
The console output reflects the changes correctly.
### Actual behavior
```
Unhandled exception. System.BadImageFormatException: An attempt was made to load a program with an incorrect format.
(0x8007000B)
at osu.Game.Overlays.Profile.Faulty.<>c.b__0_0(Model s)
at osu.Game.Overlays.Profile.Faulty.Method()
at Program.$(String[] args) in /Users/salman/Projects/osu/ExecutableProject/Program.cs:line 9
```
### Regression?
_No response_
### Known Workarounds
_No response_
### Configuration
```
.NET SDK:
Version: 8.0.303
Commit: 29ab8e3268
Workload version: 8.0.300-manifests.7ccdde63
MSBuild version: 17.10.4+10fbfbf2e
Runtime Environment:
OS Name: Mac OS X
OS Version: 14.1
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/8.0.303/
.NET workloads installed:
[ios]
Installation Source: SDK 8.0.300
Manifest Version: 17.2.8078/8.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.ios/17.2.8078/WorkloadManifest.json
Install Type: FileBased
[android]
Installation Source: SDK 8.0.300
Manifest Version: 34.0.113/8.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.android/34.0.113/WorkloadManifest.json
Install Type: FileBased
Host:
Version: 8.0.7
Architecture: arm64
Commit: 2aade6beb0
.NET SDKs installed:
6.0.417 [/usr/local/share/dotnet/sdk]
8.0.100 [/usr/local/share/dotnet/sdk]
8.0.302 [/usr/local/share/dotnet/sdk]
8.0.303 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.25 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.25 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
/Users/salman/Projects/osu/global.json
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
```
I'm not sure it's specific to that configuration.
### Other information
- Changing the namespace of the `osu.Game/Overlays/Profile/Header/Components/Faulty.cs` file may hide the issue, particularly any namespace that isn't part of the `osu.Game.Overlays.Profile` subtree
- This could be an indicator that there are other files in the `osu.Game.Overlays.Profile` namespace that are relevant to the cause of this bug.
- Removing or changing the parameter type of the `osu.Game.Overlays.Profile.Model.Death(bool?)` method
- Removing all files in the `osu.Game` project except for the `Faulty.cs` file also hides the issue.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.