Repository: dotnet/runtime
File: src/coreclr/System.Private.CoreLib/src/System/Reflection/MdImport.cs (C#)

Code before:
            out byte* marshalCookie,
            out int marshalCookieLength,
            out int iidParamIndex);

        internal static unsafe MarshalAsAttribute GetMarshalAs(ConstArray nativeType, RuntimeModule scope)
        {
            if (!GetMarshalAs(
                    nativeType.Signature,
                    nativeType.Length,
                    out int unmanagedTypeRaw,
                    out int safeArraySubTypeRaw,
                    out byte* safeArrayUserDefinedSubTypeRaw,
                    out int safeArrayUserDefinedSubTypeLength,
                    out int arraySubTypeRaw,
                    out int sizeParamIndex,
                    out int sizeConst,
                    out byte* marshalTypeRaw,
                    out int marshalTypeLength,
                    out byte* marshalCookieRaw,
                    out int marshalCookieLength,
                    out int iidParamIndex))
            {
                throw new BadImageFormatException();
            }

            string? safeArrayUserDefinedTypeName = safeArrayUserDefinedSubTypeRaw == null || safeArrayUserDefinedSubTypeLength == 0
                ? null
                : Text.Encoding.UTF8.GetString(new ReadOnlySpan<byte>(safeArrayUserDefinedSubTypeRaw, safeArrayUserDefinedSubTypeLength));
            string? marshalTypeName = marshalTypeRaw == null || marshalTypeLength == 0
                ? null
                : Text.Encoding.UTF8.GetString(new ReadOnlySpan<byte>(marshalTypeRaw, marshalTypeLength));
            string? marshalCookie = marshalCookieRaw == null || marshalCookieLength == 0
                ? null
                : Text.Encoding.UTF8.GetString(new ReadOnlySpan<byte>(marshalCookieRaw, marshalCookieLength));

            RuntimeType? safeArrayUserDefinedType = null;

            try
            {
                safeArrayUserDefinedType = string.IsNullOrEmpty(safeArrayUserDefinedTypeName) ? null :
                    TypeNameResolver.GetTypeReferencedByCustomAttribute(safeArrayUserDefinedTypeName, scope);
            }
            catch (TypeLoadException)
            {
                // The user may have supplied a bad type name string causing this TypeLoadException
                Debug.Assert(safeArrayUserDefinedTypeName is not null);
            }

            RuntimeType? marshalTypeRef = null;

            try

Review comment (suggestion):
@copilot+claude-opus-4.6 Delete the checks for zero lengths. They are unnecessary subtle behavior change.

Code after:
            out int marshalTypeLength,
            out byte* marshalCookie,
            out int marshalCookieLength,
            out int iidParamIndex);

        internal static unsafe MarshalAsAttribute GetMarshalAs(ConstArray nativeType, RuntimeModule scope)
        {
            if (!GetMarshalAs(
                    nativeType.Signature,
                    nativeType.Length,
                    out int unmanagedTypeRaw,
                    out int safeArraySubTypeRaw,
                    out byte* safeArrayUserDefinedSubTypeRaw,
                    out int safeArrayUserDefinedSubTypeLength,
                    out int arraySubTypeRaw,
                    out int sizeParamIndex,
                    out int sizeConst,
                    out byte* marshalTypeRaw,
                    out int marshalTypeLength,
                    out byte* marshalCookieRaw,
                    out int marshalCookieLength,
                    out int iidParamIndex))
            {
                throw new BadImageFormatException();
            }

            string? safeArrayUserDefinedTypeName = safeArrayUserDefinedSubTypeRaw == null
                ? null
                : Text.Encoding.UTF8.GetString(new ReadOnlySpan<byte>(safeArrayUserDefinedSubTypeRaw, safeArrayUserDefinedSubTypeLength));
            string? marshalTypeName = marshalTypeRaw == null
                ? null
                : Text.Encoding.UTF8.GetString(new ReadOnlySpan<byte>(marshalTypeRaw, marshalTypeLength));
            string? marshalCookie = marshalCookieRaw == null
                ? null
                : Text.Encoding.UTF8.GetString(new ReadOnlySpan<byte>(marshalCookieRaw, marshalCookieLength));

            RuntimeType? safeArrayUserDefinedType = null;

            try
            {
                safeArrayUserDefinedType = string.IsNullOrEmpty(safeArrayUserDefinedTypeName) ? null :
                    TypeNameResolver.GetTypeReferencedByCustomAttribute(safeArrayUserDefinedTypeName, scope);
            }
            catch (TypeLoadException)
            {
                // The user may have supplied a bad type name string causing this TypeLoadException
                Debug.Assert(safeArrayUserDefinedTypeName is not null);
            }

            RuntimeType? marshalTypeRef = null;