diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs index f9b419a5d8c124..d848d2dc0810e7 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs @@ -658,14 +658,6 @@ public static RuntimeTypeHandle CreateEEType(TypeDesc type, TypeBuilderState sta pTemplateEEType = templateTypeHandle.ToEETypePtr(); } - else if (type.IsMdArray || (type.IsSzArray && ((ArrayType)type).ElementType.IsPointer)) - { - // Multidimensional arrays and szarrays of pointers don't implement generic interfaces and - // we don't need to do much for them in terms of type building. We can pretty much just take - // the MethodTable for any of those, massage the bits that matter (GCDesc, element type, - // component size,...) to be of the right shape and we're done. - pTemplateEEType = typeof(object[,]).TypeHandle.ToEETypePtr(); - } else { Debug.Assert(state.TemplateType != null && !state.TemplateType.RuntimeTypeHandle.IsNull()); diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeBuilderState.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeBuilderState.cs index 7cf922fd75f4d7..38ca0c0bb8ad14 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeBuilderState.cs +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeBuilderState.cs @@ -56,9 +56,9 @@ public TypeDesc TemplateType { if (!_templateComputed) { - // Multidimensional arrays and szarrays of pointers don't implement generic interfaces and are special cases. They use + // Multidimensional arrays don't implement generic interfaces and are special cases. They use // typeof(object[,]) as their template. - if (TypeBeingBuilt.IsMdArray || (TypeBeingBuilt.IsSzArray && ((ArrayType)TypeBeingBuilt).ElementType.IsPointer)) + if (TypeBeingBuilt.IsMdArray) { _templateType = TypeBeingBuilt.Context.ResolveRuntimeTypeHandle(typeof(object[,]).TypeHandle); _templateTypeLoaderNativeLayout = false; @@ -67,6 +67,17 @@ public TypeDesc TemplateType return _templateType; } + // Arrays of pointers don't implement generic interfaces and are special cases. They use + // typeof(char*[]) as their template. + if (TypeBeingBuilt.IsSzArray && ((ArrayType)TypeBeingBuilt).ElementType.IsPointer) + { + _templateType = TypeBeingBuilt.Context.ResolveRuntimeTypeHandle(typeof(char*[]).TypeHandle); + _templateTypeLoaderNativeLayout = false; + _nativeLayoutComputed = _nativeLayoutTokenComputed = _templateComputed = true; + + return _templateType; + } + // Locate the template type and native layout info _templateType = TemplateLocator.TryGetTypeTemplate(TypeBeingBuilt, ref _nativeLayoutInfo); Debug.Assert(_templateType == null || !_templateType.RuntimeTypeHandle.IsNull());