Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generic list of value types with sequential layout and pack size -> BUG?

The following code throws an ExecutionEngineException when I run the release build executable (start exe file). Is this a bug or is it normal behavior?

value type with pack size = 1:

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct RunLong
{
    public byte Count;
    public long Value;

    public RunLong(byte count, long value)
    {
        Count = count;
        Value = value;
    }
}

Using the struct in a generic List(T), adding values and getting or setting its value property makes the executable crash if it has been built in release mode. The crash doesn't occur when the executable is built in debug mode or when running the code inside visual studio debugger (release or debug mode).

List<RunLong> runs = new List<RunLong>(1024);

for (int i = 0; i < 1000; i++)
{
    runs.Add(new RunLong(1, i));
}

RunLong last = runs[runs.Count - 1];

last.Count = (byte)(last.Count + 1);

 runs[runs.Count - 1] = last;

Can somebody confirm this? Is there a reasonable explanation?

I am running VS 2010, .net 4, Win XP SP3

Thanks in advance!

like image 363
user410903 Avatar asked Aug 04 '10 16:08

user410903


1 Answers

This issue was fixed in MS11-028 last week. See my weblog for details.

like image 110
Jeroen Frijters Avatar answered Sep 19 '22 03:09

Jeroen Frijters