peass-ng/PEASS-ng · error · ArgumentException

{0} {1} is not writeable by {2}.

Error message

{0} {1} is not writeable by {2}.

What it means

ObjectMemberAccessor.RegisterMember applies YamlSerializeAttribute configuration to a member. If the attribute demands Assign or Content serialization for a value-type member that has no setter (read-only), the accessor cannot write it, so it throws ArgumentException('{0} {1} is not writeable by {2}.').

Source

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

            MemberInfo accessor = new MemberInfo();

            accessor.Type = mType;
            accessor.Get = get;
            accessor.Set = set;

            if(set!=null){ // writeable ?
                accessor.SerializeMethod = YamlSerializeMethod.Assign;
            } else {
                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

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Add a setter to the member (public or private) so Assign/Content serialization can write it.
  2. Change the attribute to YamlSerializeMethod.Content for reference types or Never/Member for read-only members.
  3. Remove the YamlSerializeAttribute so the member falls back to default handling.
  4. Make the member a mutable field instead of a get-only property.

Example fix

// before
[YamlSerialize(YamlSerializeMethod.Assign)]
public Size Dim { get; } // read-only value type -> throws
// after
[YamlSerialize(YamlSerializeMethod.Assign)]
public Size Dim { get; set; }
Defensive patterns

Strategy: validation

Validate before calling

var p = type.GetProperty(name); bool ok = p != null && (p.CanWrite || attr.SerializeMethod != YamlSerializeMethod.Assign);

Type guard

static bool IsWritableForAssign(PropertyInfo p) => p != null && p.CanWrite;

Try / catch

try { RegisterMember(m, set, get); } catch (ArgumentException ex) when (ex.Message.Contains("is not writeable")) { useContentMethodInstead(); }

Prevention

When it happens

Trigger: A read-only property or readonly field whose type is a struct, annotated with [YamlSerialize(YamlSerializeMethod.Assign)] (or Content for value types) — or any read-only member with SerializeMethod=Assign — during serializer setup.

Common situations: Auto-properties without a setter on immutable structs; records/DTO refactored to read-only while keeping old serialization attributes; fields exposed via get-only properties.

Related errors


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