@@ -293,7 +293,7 @@ private static Type EmitType(IList<DynamicProperty> properties, bool createParam
293293 // Use object-based equality comparer for types that are not publicly accessible from
294294 // the dynamic assembly (e.g., compiler-generated anonymous types). Calling
295295 // EqualityComparer<T>.get_Default() for a non-public T will throw MethodAccessException.
296- var fieldTypeIsAccessible = IsTypePubliclyAccessible ( fieldType ) ;
296+ var fieldTypeIsAccessible = IsTypePubliclyAccessible ( fieldType . GetTypeInfo ( ) ) ;
297297 var equalityType = fieldTypeIsAccessible ? fieldType : typeof ( object ) ;
298298 var equalityComparerT = EqualityComparer . MakeGenericType ( equalityType ) ;
299299
@@ -437,10 +437,10 @@ private static Type EmitType(IList<DynamicProperty> properties, bool createParam
437437 /// type arguments in EqualityComparer<T> from a dynamic assembly without causing
438438 /// a <see cref="MethodAccessException"/> at runtime.
439439 /// </summary>
440- private static bool IsTypePubliclyAccessible ( Type type )
440+ private static bool IsTypePubliclyAccessible ( TypeInfo typeInfo )
441441 {
442442 // Check if the type itself is public
443- if ( ! type . IsPublic && ! type . IsNestedPublic )
443+ if ( ! typeInfo . IsPublic && ! typeInfo . IsNestedPublic )
444444 {
445445 return false ;
446446 }
@@ -449,9 +449,9 @@ private static bool IsTypePubliclyAccessible(Type type)
449449 // all type arguments must also be publicly accessible.
450450 // Generic type definitions (e.g., List<>) have unbound type parameters
451451 // which are not concrete types and should not be checked.
452- if ( type . IsGenericType && ! type . IsGenericTypeDefinition )
452+ if ( typeInfo . IsGenericType && ! typeInfo . IsGenericTypeDefinition )
453453 {
454- return type . GetGenericArguments ( ) . All ( IsTypePubliclyAccessible ) ;
454+ return typeInfo . GetGenericArguments ( ) . All ( t => IsTypePubliclyAccessible ( t . GetTypeInfo ( ) ) ) ;
455455 }
456456
457457 return true ;
0 commit comments