-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Mono] System.Runtime.Tests fail with TypeLoadException #94086
Comments
Tagging subscribers to this area: @dotnet/area-system-runtime Issue DetailsIn #88620 I've added a very simple code that performs following checks: private static void ValidateArrayType(Type arrayType)
{
if (!arrayType.IsArray)
ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_HasToBeArrayClass, ExceptionArgument.arrayType);
ValidateElementType(arrayType.GetElementType()!);
}
private static void ValidateElementType(Type elementType)
{
while (elementType.IsArray)
{
elementType = elementType.GetElementType()!;
}
if (elementType.IsByRef || elementType.IsByRefLike)
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ByRefLikeArray);
if (elementType == typeof(void))
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_VoidArray);
if (elementType.ContainsGenericParameters)
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_OpenType);
} The tests pass on CLR and NativeAOT, but fail on Mono: System.Tests.ArrayTests.CreateInstanceFromArrayType_NotSupportedArrayType_ThrowsNotSupportedException(elementType: typeof(System.Void)) [FAIL]
Assert.Throws() Failure: Exception type was not an exact match
Expected: typeof(System.NotSupportedException)
Actual: typeof(System.TypeLoadException)
---- System.TypeLoadException : Could not load array element class, due to: Error getting the interfaces of System.Void[] due to Error Loading class assembly:/root/helix/work/correlation/shared/Microsoft.NETCore.App/9.0.0/System.Private.CoreLib.dll type:IList`1 member:(null) assembly:/root/helix/work/correlation/shared/Microsoft.NETCore.App/9.0.0/System.Private.CoreLib.dll type:Void[] member:(null)
Stack Trace:
/_/src/libraries/System.Runtime/tests/System/ArrayTests.cs(1957,0): at System.Tests.ArrayTests.CreateInstanceFromArrayType_NotSupportedArrayType_ThrowsNotSupportedException(Type elementType)
/_/src/mono/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.Mono.cs(22,0): at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
/_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs(178,0): at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
----- Inner Stack Trace -----
/_/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs(287,0): at System.RuntimeTypeHandle.GetElementType(RuntimeType type)
/_/src/libraries/System.Private.CoreLib/src/System/RuntimeType.cs(96,0): at System.RuntimeType.GetElementType()
/_/src/libraries/System.Private.CoreLib/src/System/Array.cs(338,0): at System.Array.ValidateArrayType(Type arrayType)
/_/src/libraries/System.Private.CoreLib/src/System/Array.cs(261,0): at System.Array.CreateInstanceFromArrayType(Type arrayType, Int32[] lengths)
/_/src/libraries/System.Runtime/tests/System/ArrayTests.cs(1957,0): at System.Tests.ArrayTests.<>c__DisplayClass90_0.<CreateInstanceFromArrayType_NotSupportedArrayType_ThrowsNotSupportedException>b__1()
System.Threading.Tests.PeriodicTimerTests.PeriodicTimer_NoActiveOperations_TimerNotRooted [SKIP] What is really strange is that due to this failure, other tests that were passing so far started to fail as well:
I was not able to repro it with a standalone app: using System.Reflection;
namespace ArrayOfVoid
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine($"IsMono: {Type.GetType("Mono.RuntimeStructs") != null}");
Console.WriteLine(typeof(void).MakeArrayType().IsArray);
Console.WriteLine(typeof(void).MakeArrayType().MakeArrayType().IsArray);
Console.WriteLine(typeof(void).MakeArrayType().GetElementType()!.IsArray);
Console.WriteLine(typeof(void).MakeArrayType().MakeArrayType().GetElementType()!.IsArray);
Console.WriteLine(typeof(void).MakeArrayType().MakeArrayType().GetElementType()!.GetElementType()!.IsArray);
}
}
} dotnet publish -c Release -r win-x64 --self-contained /p:UseMonoRuntime=true
.\bin\Release\net8.0\win-x64\publish\ArrayOfVoid.exe
This test is trying to create an array of arrays of void, I suspect that this is somehow triggering some edge case. BTW some of the tests are marked with
|
/cc @vargaz |
Will look into it. AFAIK, void[] is not a valid type, so some operations on it will cause type load exceptions, mono might throw them in different places than coreclr. |
The CoreCLR type loader allowed creating arrays of System.Void. Many operations with these invalid array types failed, often in inscrutable ways. For example, GetInterfaces() call failed with type load exception of IEnumerable type. The exact failure modes are different between runtimes. It is better to disallow creating these invalid array types in the first place, across all runtimes, to make the behavior robust and consistent. Related to dotnet#88620 Fixes dotnet#94086
The CoreCLR type loader allowed creating arrays of System.Void. Many operations with these invalid array types failed, often in inscrutable ways. For example, GetInterfaces() call failed with type load exception of IEnumerable type. The exact failure modes are different between runtimes. It is better to disallow creating these invalid array types in the first place, across all runtimes, to make the behavior robust and consistent. Related to #88620 Fixes #94086
In #88620 I've added a very simple code that performs following checks:
The tests pass on CLR and NativeAOT, but fail on Mono:
What is really strange is that due to this failure, other tests that were passing so far started to fail as well:
I was not able to repro it with a standalone app:
This test is trying to create an array of arrays of void, I suspect that this is somehow triggering some edge case.
BTW some of the tests are marked with
[ActiveIssue("https://github.com/dotnet/runtime/issues/52072"
despite the fact that #52072 has been closed (cc @mdh1418)The text was updated successfully, but these errors were encountered: