Describe the bug
The following code throws System.AccessViolationException:
int height = 720;
int width = 1280;
byte[] storage = new byte[width * height * sizeof(int)];
Memory2D<int> data = storage
.AsMemory()
.Cast<byte, int>()
.AsMemory2D(height: height, width: width);
Memory2D<int> slice = data.Slice(
row: height / 2,
column: 0,
height: height / 2,
width: width);
int total = 0;
foreach (int v in slice.Span)
{
total += v;
}
Regression
No response
Steps to reproduce
Create a project targeting net7.0, paste the above code into the `Main` method, run it.
Expected behavior
The code is supposed to calculate a sum of all values in the slice (in this case, 0).
Screenshots

IDE and version
VS 2022
IDE version
17.4.4
Nuget packages
Nuget package version(s)
8.2.0
Additional context
The problem disappears when there's no Cast() (so, we are summing over a Span of bytes). It also disappears when there's no Slice() (so, we are summing over data instead of slice).
Help us help you
No, just wanted to report this
Describe the bug
The following code throws
System.AccessViolationException:Regression
No response
Steps to reproduce
Expected behavior
The code is supposed to calculate a sum of all values in the slice (in this case, 0).
Screenshots
IDE and version
VS 2022
IDE version
17.4.4
Nuget packages
Nuget package version(s)
8.2.0
Additional context
The problem disappears when there's no
Cast()(so, we are summing over aSpanof bytes). It also disappears when there's noSlice()(so, we are summing overdatainstead ofslice).Help us help you
No, just wanted to report this