diff --git a/src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Validation.cs b/src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Validation.cs index 6c0b5f9fe2e693..ff34b94f3b43a6 100644 --- a/src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Validation.cs +++ b/src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Validation.cs @@ -266,7 +266,7 @@ private static TypeDesc EnsureLoadableTypeUncached(TypeDesc type) if (parameterizedType.IsArray) { LayoutInt elementSize = parameterType.GetElementSize(); - if (!elementSize.IsIndeterminate && elementSize.AsInt >= ushort.MaxValue) + if (!elementSize.IsIndeterminate && elementSize.AsInt > ushort.MaxValue) { // Element size over 64k can't be encoded in the GCDesc ThrowHelper.ThrowTypeLoadException(ExceptionStringID.ClassLoadValueClassTooLarge, parameterType); diff --git a/src/tests/Loader/classloader/InlineArray/MaxArrayElementSize.cs b/src/tests/Loader/classloader/InlineArray/MaxArrayElementSize.cs new file mode 100644 index 00000000000000..d226e967b2ae30 --- /dev/null +++ b/src/tests/Loader/classloader/InlineArray/MaxArrayElementSize.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Runtime.CompilerServices; +using Xunit; + +public unsafe class MaxArrayElementSize +{ + [InlineArray(65535)] + struct MaxSizedArrayElement + { + byte b; + } + + [Fact] + public static int TestEntryPoint() + { + return sizeof(MaxSizedArrayElement) == ushort.MaxValue + && new MaxSizedArrayElement[1].Length == 1 + ? 100 + : 101; + } +} diff --git a/src/tests/Loader/classloader/InlineArray/MaxArrayElementSize.csproj b/src/tests/Loader/classloader/InlineArray/MaxArrayElementSize.csproj new file mode 100644 index 00000000000000..042e92733f2758 --- /dev/null +++ b/src/tests/Loader/classloader/InlineArray/MaxArrayElementSize.csproj @@ -0,0 +1,8 @@ + + + true + + + + +