Closed
Description
Source Code
using System;
using System.Runtime.InteropServices;
namespace ConsoleApp2
{
[StructLayout(LayoutKind.Explicit, Pack = 1)]
struct Union
{
[FieldOffset(0)]
public byte[] Bytes;
[FieldOffset(0)]
public int[] Ints;
}
class Program
{
static void Main(string[] args)
{
var union = new Union();
union.Bytes = new byte[64];
union.Bytes[0] = 1;
union.Bytes[1] = 2;
Console.WriteLine("Int: " + union.Ints[0] + " " + union.Ints[1]);
}
}
}
When calling ICorDebugObjectValue.GetFieldValue
, with the correct ICorDebugClass for the Union
struct and with the MetadataToken for Ints
, the return ICorDebugValue's ICorDebugType ends up with the wrong type being bytes[]
(instead of int[]
)
However, this works correctly when given the MetadataToken for Bytes
.
We use ICorDebugValue2.GetExactType
to get the type.
If you look at the locals or watch union
in the EE window, both Bytes
and Ints
are displayed as byte[]
.