Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>2018-02-26 20:27:38 +0300
committerJan Kotas <jkotas@microsoft.com>2018-02-26 20:27:38 +0300
commit10dfb18be0deff4dfeda15a453e7a22dbbc5d9c3 (patch)
treed52ec01df96eb1ef217ea526fd60deec3ecc946f /src/System.Private.Reflection.Core
parentc8ccd5b2d5ca8f9bd276fa233b826b19787c9476 (diff)
Move check for IsByRefLike to MakeArrayType (#5439)
Having a call to `IsByRefLike` in the type unifier meant that an app that uses a simple `typeof()` would require the full reflection stack to be present in the image (all of the custom attribute resolution, method resolution, etc.). This is a step towards having a more pay for play framework (a hello world EXE really should not have the full reflection stack compiled in it).
Diffstat (limited to 'src/System.Private.Reflection.Core')
-rw-r--r--src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/TypeUnifier.cs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/TypeUnifier.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/TypeUnifier.cs
index 98d338020..aa3f0dc82 100644
--- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/TypeUnifier.cs
+++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/TypeUnifier.cs
@@ -210,6 +210,14 @@ namespace System.Reflection.Runtime.TypeInfos
if (elementTypeHandle.IsNull())
return default(RuntimeTypeHandle);
+ // The check is here on purpose - one of the implementations of IsByRefLike contains a custom attribute
+ // search and those are very expensive from size on disk footprint perspective. We purposefully
+ // place this call in a path that won't be part of the executable image unless more advanced reflection services
+ // are also needed ("pay for play"). We really don't want a typeof() to push the app into requiring the full reflection
+ // stack to be compiled into the final executable.
+ if (elementType.IsByRefLike)
+ throw new TypeLoadException(SR.Format(SR.ArgumentException_InvalidArrayElementType, elementType));
+
RuntimeTypeHandle typeHandle;
if (!multiDim)
{
@@ -272,7 +280,7 @@ namespace System.Reflection.Runtime.TypeInfos
{
Debug.Assert(multiDim || rank == 1);
- if (elementType.IsByRef || elementType.IsByRefLike)
+ if (elementType.IsByRef)
throw new TypeLoadException(SR.Format(SR.ArgumentException_InvalidArrayElementType, elementType));
// We only permit creating parameterized types if the pay-for-play policy specifically allows them *or* if the result