开发者

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!


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


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).

  • http://connect.microsoft.com/visualstudio
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜