peass-ng/PEASS-ng · error · InvalidOperationException

{0} {1} of {2} is not an array. Can not be serialized as bin

Error message

{0} {1} of {2} is not an array. Can not be serialized as binary.

What it means

ObjectMemberAccessor.RegisterMember validates Binary serialization requirements: YamlSerializeMethod.Binary is only supported for arrays whose element type is a pure (blittable, non-reference) value type. If the member type is not an array, RegisterMember throws InvalidOperationException('{0} {1} of {2} is not an array. Can not be serialized as binary.').

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/YamlSerializer/ObjectMemberAccessor.cs:147

                accessor.SerializeMethod = YamlSerializeMethod.Never;
                if ( mType.IsClass )
                    accessor.SerializeMethod = YamlSerializeMethod.Content;
            }
            var attr1 = m.GetAttribute<YamlSerializeAttribute>();
            if ( attr1 != null ) { // specified
                if ( set == null ) { // read only member
                    if ( attr1.SerializeMethod == YamlSerializeMethod.Assign ||
                         ( mType.IsValueType && accessor.SerializeMethod == YamlSerializeMethod.Content ) )
                        throw new ArgumentException("{0} {1} is not writeable by {2}."
                            .DoFormat(mType.FullName, m.Name, attr1.SerializeMethod.ToString()));
                }
                accessor.SerializeMethod = attr1.SerializeMethod;
            }
            if ( accessor.SerializeMethod == YamlSerializeMethod.Never )
                return; // no need to register
            if ( accessor.SerializeMethod == YamlSerializeMethod.Binary ) {
                if ( !mType.IsArray )
                    throw new InvalidOperationException("{0} {1} of {2} is not an array. Can not be serialized as binary."
                        .DoFormat(mType.FullName, m.Name, type.FullName));
                if ( !TypeUtils.IsPureValueType(mType.GetElementType()) )
                    throw new InvalidOperationException(
                        "{0} is not a pure ValueType. {1} {2} of {3} can not serialize as binary."
                        .DoFormat(mType.GetElementType(), mType.FullName, m.Name, type.FullName));
            }

            // ShouldSerialize
            //      YamlSerializeAttribute(Never) => false
            //      ShouldSerializeSomeProperty => call it
            //      DefaultValueAttribute(default) => compare to it
            //      otherwise => true
            var shouldSerialize = type.GetMethod("ShouldSerialize" + m.Name,
                System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic,
                null, Type.EmptyTypes, new System.Reflection.ParameterModifier[0]);
            if ( shouldSerialize != null && shouldSerialize.ReturnType == typeof(bool) && accessor.ShouldSeriealize == null )
                accessor.ShouldSeriealize = obj => (bool)shouldSerialize.Invoke(obj, EmptyObjectArray);
            var attr2 = m.GetAttribute<DefaultValueAttribute>();

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Change the member type to a proper array (e.g. T[] or byte[]).
  2. Change the attribute to a supported SerializeMethod (Content/Member) for non-array types.
  3. Remove the Binary attribute and rely on default YAML serialization.
  4. Keep a byte[] shadow property for binary serialization and map to/from the collection.

Example fix

// before
[YamlSerialize(YamlSerializeMethod.Binary)]
public List<byte> Data { get; set; } // not an array -> throws
// after
[YamlSerialize(YamlSerializeMethod.Binary)]
public byte[] Data { get; set; }
Defensive patterns

Strategy: type-guard

Validate before calling

bool ok = mType.IsArray && TypeUtils.IsPureValueType(mType.GetElementType());

Type guard

static bool IsBinarySerializable(Type t) => t != null && t.IsArray && TypeUtils.IsPureValueType(t.GetElementType());

Try / catch

try { RegisterMember(m, set, get); } catch (InvalidOperationException ex) when (ex.Message.Contains("not an array")) { accessor.SerializeMethod = YamlSerializeMethod.Content; }

Prevention

When it happens

Trigger: Annotating a member of type List<T>, byte-like struct, or any non-array type with [YamlSerialize(YamlSerializeMethod.Binary)] and instantiating the accessor.

Common situations: Migrating members from byte[] to List<byte> while keeping the Binary attribute; applying Binary to multidimensional or jagged containers assumed to be arrays; copy-pasted attributes across members.

Related errors


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/860055e5723a7ae9. Report an issue: GitHub.