-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unsafe code crashes with System.BadImageFormatException when built with latest .NET 7 preview SDK #74306
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
@NoahStolk Do you get the same results with later daily builds? You can download from the dotnet/installer repo. Also, is it possible to get a stack with a native debugger? |
I installed |
perhaps it was an issue that later fixed itself in newer daily builds? |
we will investigate if this was an interim bug which was fixed recently. Thanks |
This bug has indeed been fixed. Tested it out with several builds, and the latest I could get it to repro was the newest Preview 7 build (7.0.100-preview.7.22411.2). After that, it no longer repros and the app exits successfully, as expected. Closing now. |
Maybe this was dotnet/roslyn#62392? It was reverted but made it into preview 7 -- perhaps the IL produced is invalid. |
I read through this PR and it sounds reasonable. Whenever I run this failing test, it only loads System.Private.CoreLib.dll, the test's dll, and System.Runtime.dll, then throws the exception. This points to it encountering some weird stuff while attempting to load whichever dll comes next (it differs from app to app). The other thing is I wasn't able to get a managed stack trace. The native stack trace looks like this:
The exception is being cast as the worker attempts to do its job of running the app. Is there a way to know when that Roslyn change made it to the runtime and sdk? Just out of curiosity, it would be nice to confirm this is indeed the case :) |
Can you check the IL for |
Yes that's what it's doing. This is how the // Program
using System;
private static void <Main>$(string[] args)
{
Test();
unsafe static void Test()
{
byte*[] test = GC.AllocateUninitializedArray<byte*>(0, pinned: false);
}
} |
Ok, looks like that was the issue then. |
Description
The following sample program crashes with
System.BadImageFormatException
when built with the latest .NET 7 preview SDK (7.0.100-preview.7.22377.5
). It runs fine when built with the previous preview version (7.0.100-preview.6.22352.1
).I've been using .NET 7 for a while and recently pushed an update for my package. Previous versions were built with version
7.0.100-preview.6.22352.1
and worked fine. When using version7.0.100-preview.7.22377.5
, a call to an unsafe method crashed withSystem.BadImageFormatException
. I tried to narrow down the problem and came up with a minimal sample that consistently crashes when built with the latest version.Reproduction Steps
Program.cs
Test.csproj
global.json
dotnet run
.It crashes with:
When changing the SDK version to
6.0.400
or7.0.100-preview.6.22352.1
(the previous preview version) inglobal.json
, the program runs fine.The configuration (debug/release) and architecture (x64/x86) do not seem to matter.
Expected behavior
I expect no runtime errors when running this application. Am I missing a breaking change? I checked the breaking changes for .NET 7 but none of them stood out to me.
Actual behavior
The program crashes with
System.BadImageFormatException
.Regression?
No response
Known Workarounds
No response
Configuration
SDK version
7.0.100-preview.7.22377.5
OS
Windows 10 Pro 19044.1889 64-bit
Architecture
x64
Other information
No response
The text was updated successfully, but these errors were encountered: