{"record":{"id":"bbcc1a0403bd413e","repo":"peass-ng/PEASS-ng","slug":"0-1-is-not-writeable-by-2","errorCode":null,"errorMessage":"{0} {1} is not writeable by {2}.","messagePattern":"(.+?) (.+?) is not writeable by (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/YamlSerializer/ObjectMemberAccessor.cs","lineNumber":138,"sourceCode":"            MemberInfo accessor = new MemberInfo();\n\n            accessor.Type = mType;\n            accessor.Get = get;\n            accessor.Set = set;\n\n            if(set!=null){ // writeable ?\n                accessor.SerializeMethod = YamlSerializeMethod.Assign;\n            } else {\n                accessor.SerializeMethod = YamlSerializeMethod.Never;\n                if ( mType.IsClass )\n                    accessor.SerializeMethod = YamlSerializeMethod.Content;\n            }\n            var attr1 = m.GetAttribute<YamlSerializeAttribute>();\n            if ( attr1 != null ) { // specified\n                if ( set == null ) { // read only member\n                    if ( attr1.SerializeMethod == YamlSerializeMethod.Assign ||\n                         ( mType.IsValueType && accessor.SerializeMethod == YamlSerializeMethod.Content ) )\n                        throw new ArgumentException(\"{0} {1} is not writeable by {2}.\"\n                            .DoFormat(mType.FullName, m.Name, attr1.SerializeMethod.ToString()));\n                }\n                accessor.SerializeMethod = attr1.SerializeMethod;\n            }\n            if ( accessor.SerializeMethod == YamlSerializeMethod.Never )\n                return; // no need to register\n            if ( accessor.SerializeMethod == YamlSerializeMethod.Binary ) {\n                if ( !mType.IsArray )\n                    throw new InvalidOperationException(\"{0} {1} of {2} is not an array. Can not be serialized as binary.\"\n                        .DoFormat(mType.FullName, m.Name, type.FullName));\n                if ( !TypeUtils.IsPureValueType(mType.GetElementType()) )\n                    throw new InvalidOperationException(\n                        \"{0} is not a pure ValueType. {1} {2} of {3} can not serialize as binary.\"\n                        .DoFormat(mType.GetElementType(), mType.FullName, m.Name, type.FullName));\n            }\n\n            // ShouldSerialize\n            //      YamlSerializeAttribute(Never) => false","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/YamlSerializer/ObjectMemberAccessor.cs#L120-L156","documentation":"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}.').","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add a setter to the member (public or private) so Assign/Content serialization can write it.","Change the attribute to YamlSerializeMethod.Content for reference types or Never/Member for read-only members.","Remove the YamlSerializeAttribute so the member falls back to default handling.","Make the member a mutable field instead of a get-only property."],"exampleFix":"// before\n[YamlSerialize(YamlSerializeMethod.Assign)]\npublic Size Dim { get; } // read-only value type -> throws\n// after\n[YamlSerialize(YamlSerializeMethod.Assign)]\npublic Size Dim { get; set; }","handlingStrategy":"validation","validationCode":"var p = type.GetProperty(name); bool ok = p != null && (p.CanWrite || attr.SerializeMethod != YamlSerializeMethod.Assign);","typeGuard":"static bool IsWritableForAssign(PropertyInfo p) => p != null && p.CanWrite;","tryCatchPattern":"try { RegisterMember(m, set, get); } catch (ArgumentException ex) when (ex.Message.Contains(\"is not writeable\")) { useContentMethodInstead(); }","preventionTips":["Audit YamlSerialize attributes after refactoring to read-only members","Prefer Content method for immutable members","Add a startup test that constructs accessors for all annotated types"],"tags":["csharp","yaml","serialization","reflection"],"backgroundTag":"read-only-member-serialization","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}