views:

57

answers:

1

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!

+1  A: 

This does appear on the surface to be a bug in the x86 JIT engine. This only repros under the following circumstances

  • Compile in Retail
  • Compile for x86
  • Run without Visual Studio Debugger (repros under WinDbg though)

It does not repro in amd64 mode though which makes me suspect it's either

  1. An alignment issue (aka. bug in your code)
  2. A x86 JIT issue

I'm not an expert in alignment by any means but I believe your code to be correct. Please file a bug on connect to make sure the issue is investigated and add the bug link to the comment section of my answer (I'd like to track it internally).

JaredPar
Thanks for the reply, I have posted the problem at connect:https://connect.microsoft.com/VisualStudio/feedback/details/583519/generic-list-of-value-types-with-sequential-layout-and-pack-size-x86-jit-engine-bug
@jassman, could you check your link, it appears to be incorrect. I searched for the issue and could not find it.
JaredPar
tried this link with another live account and it works for me:https://connect.microsoft.com/VisualStudio/feedback/details/583519/generic-list-of-value-types-with-sequential-layout-and-pack-size-x86-jit-engine-bug
@jassman, weird still can't see it. Is it a private issue?
JaredPar
no, the issue is configured as public