diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.cs index 06a3a6bf382d..a1c2f172c5cd 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.cs @@ -847,21 +847,10 @@ public static string GenerateProgIdForType(Type type) throw new ArgumentException(SR.Argument_NeedNonGenericType, nameof(type)); } - foreach (CustomAttributeData cad in type.GetCustomAttributesData()) + ProgIdAttribute progIdAttribute = type.GetCustomAttribute(); + if (progIdAttribute != null) { - if (cad.Constructor.DeclaringType == typeof(ProgIdAttribute)) - { - // Retrieve the PROGID string from the ProgIdAttribute. - IList caConstructorArgs = cad.ConstructorArguments; - Debug.Assert(caConstructorArgs.Count == 1, "caConstructorArgs.Count == 1"); - - CustomAttributeTypedArgument progIdConstructorArg = caConstructorArgs[0]; - Debug.Assert(progIdConstructorArg.ArgumentType == typeof(string), "progIdConstructorArg.ArgumentType == typeof(string)"); - - string strProgId = (string)progIdConstructorArg.Value; - - return strProgId ?? string.Empty; - } + return progIdAttribute.Value ?? string.Empty; } // If there is no prog ID attribute then use the full name of the type as the prog id.