I'm macking a struct consisting of several constants, vars (int and byte), and one 64kb fixed-size array of bytes. When I build using NAOT by command "dotnet publish -r win-x64 -c Release" I get error "ILC: Method will always throw because: Array of type cannot be created because base value type is too large"
I found out that if reduce the size of the array to 64Kb - 17b, then the code builds successfully. That is, if the structure is more than 16kb, then it cant to build it. What is it related to and how can I solve it? (Also I found it https://github.com/dotnet/runtime/blob/4719135a5fd6c9f22ce429ad8a211d696eae0426/src/coreclr/gc/gcdesc.h#L265), https://github.com/dotnet/runtime/blob/6246ce37ef665f5dc08b542a1ab092d90293eb62/src/coreclr/vm/array.cpp#L401-L405)
Also I was get the full error stack - https://pastebin.com/Aj8y11Nq
[StructLayout(LayoutKind.Sequential)]
public unsafe struct DChunk
{
public const byte CHUNK_SECTION_SHIFT = 11;
public const int CHUNK_SECTION_BYTES = 2 << CHUNK_SECTION_SHIFT;
public const int BLOCKS_COUNT = 2 << CHUNK_SECTION_SHIFT << 4;
public DChunk(int x, int z, byte[] blocks, bool fullChunk, byte lastChunkIndex = 15)
{
X = x;
Z = z;
fixed (byte* originalBlocksPtr = Blocks)
fixed (byte* blocksPtr = blocks)
Buffer.MemoryCopy(originalBlocksPtr, blocksPtr, blocks.Length, blocks.Length);
FullChunk = fullChunk;
LastChunkIndex = lastChunkIndex;
}
public fixed byte Blocks[BLOCKS_COUNT - 17]; //Change -17 to -16 and you will get error
public byte LastChunkIndex;
public int X, Z;
public bool FullChunk;
}
public class Program
{
static List<DChunk> chunks = new List<DChunk>();
public static void Main()
{
byte[] blocks = ;
DChunk chunk = new DChunk(0, 0, new byte[0] blocks, true, 0);
Console.WriteLine(chunk.X + " " + chunk.Z);
chunks.Add(chunk);
DChunk c = chunks[0];
chunks.RemoveAt(0);
chunks.Add(c);
}
}