From df958076289bbc3ec6d76e57451f2cf2609c3e4c Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Tue, 24 Aug 2021 14:56:43 +0200 Subject: [PATCH] [mono] Support RuntimeType.MakeGenericType with non-RuntimeType elements * Fixes https://github.com/dotnet/runtime/issues/58013 --- .../System.Runtime/tests/System/Type/TypeTests.cs | 10 ++++++++++ .../src/System/RuntimeType.Mono.cs | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System/Type/TypeTests.cs b/src/libraries/System.Runtime/tests/System/Type/TypeTests.cs index f8816f13a62ab7..a749e939d226e3 100644 --- a/src/libraries/System.Runtime/tests/System/Type/TypeTests.cs +++ b/src/libraries/System.Runtime/tests/System/Type/TypeTests.cs @@ -923,6 +923,16 @@ public void IsContextful() Assert.True(!typeof(ContextBoundClass).IsContextful); } + [Fact] + public void MakeGenericType_NonRuntimeType() + { + foreach (Type nonRuntimeType in Helpers.NonRuntimeTypes) + { + Type t = typeof(List<>).MakeGenericType(nonRuntimeType); + Assert.NotNull(t); + } + } + #region GetInterfaceMap tests public static IEnumerable GetInterfaceMap_TestData() { diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs index 2d0a4b925096e4..f6d349d99ba261 100644 --- a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs @@ -1336,8 +1336,9 @@ public override Type MakeGenericType(Type[] instantiation) for (int iCopy = 0; iCopy < instantiation.Length; iCopy++) instantiationCopy[iCopy] = instantiation[iCopy]; instantiation = instantiationCopy; - - throw new NotImplementedException(); + if (!RuntimeFeature.IsDynamicCodeSupported) + throw new PlatformNotSupportedException(); + return System.Reflection.Emit.TypeBuilderInstantiation.MakeGenericType(this, instantiation); } instantiationRuntimeType[i] = rtInstantiationElem;