-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 struct fails with primitive field only when at the end of the sequence #105064
Comments
It's likely because field offset exceeding the limit. Add a more #95193 (comment) indicates that the maximum field offset is around 2^27. |
This looks like a similar issue to #97412 However, I would expect SampleDataMemory_Works1 and SampleDataMemory_Works2 trigger the TypeLoadException as well. I will look into it. |
I actually tried setting Below are new examples showing the real boundaries I found:
As long as I declare my second field BEFORE |
As noted in #104393 (comment), we want to have the change apply for all runtimes. This will likely to through in .NET 10 as a result. |
@MichalStrehovsky since nativeaot is the only runtime left, I'm assigning this issue to you. |
Could you clarify what work you expect me to do? This is a customer running into this limit in the CoreCLR VM: runtime/src/coreclr/vm/field.h Lines 14 to 20 in 61b0020
Managed type system (as used by crossgen2 or ILC) doesn't have such limit. I don't see #104393 doing anything for this. There was a suggestion from Jan to print a better exception message but even that wasn't done in that PR (and could be done in a different PR too, since it's unrelated). |
My bad, I got crossed up between this and #97412 |
I have a project (tested with .NET6 and .NET8) with AllowUnsafeBlocks.
I then have a struct containing 2 fixed int arrays and a regular int.
The first two structs (SampleDataMemory_Works1 and SampleDataMemory_Works2) do work, the third one (SampleDataMemory_Crash1) crashes with System.TypeLoadException: Could not find or load a type. (0x80131522).
class and structs
csproj
As you can see all structs have the same size, the only thing different is the position of the the index property, all types are the same.
I wonder why we get this behaviour, assuming the size should be the same.
I can easily increase the size of the arrays even more and it still works for the first two structs, but a single int after the two fixed arrays makes it crash.
The text was updated successfully, but these errors were encountered: