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!