{"record":{"id":"1aa37df415775da8","repo":"peass-ng/PEASS-ng","slug":"can-not-serialize-non-public-type-0","errorCode":null,"errorMessage":"Can not serialize non-public type {0}.","messagePattern":"Can not serialize non-public type (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/YamlSerializer/ObjectMemberAccessor.cs","lineNumber":46,"sourceCode":"        /// 指定した型へのアクセス方法を表すインスタンスを返す\n        /// キャッシュに存在すればそれを返す\n        /// キャッシュに存在しなければ新しく作って返す\n        /// 作った物はキャッシュされる\n        /// </summary>\n        /// <param name=\"type\">クラスまたは構造体を表す型情報</param>\n        /// <returns></returns>\n        public static ObjectMemberAccessor FindFor(Type type)\n        {\n            if ( !MemberAccessors.ContainsKey(type) )\n                MemberAccessors[type] = new ObjectMemberAccessor(type);\n            return MemberAccessors[type];\n        }\n\n        private ObjectMemberAccessor(Type type)\n        {\n            /*\n            if ( !TypeUtils.IsPublic(type) )\n                throw new ArgumentException(\n                    \"Can not serialize non-public type {0}.\".DoFormat(type.FullName));\n            */ \n\n            // public properties\n            foreach ( var p in type.GetProperties(\n                    System.Reflection.BindingFlags.Instance | \n                    System.Reflection.BindingFlags.Public | \n                    System.Reflection.BindingFlags.GetProperty) ) {\n                var prop = p; // create closures with this local variable\n                // not readable or parameters required to access the property\n                if ( !prop.CanRead || prop.GetGetMethod(false) == null || prop.GetIndexParameters().Count() != 0 )\n                    continue;\n                Func<object, object> get = obj => prop.GetValue(obj, EmptyObjectArray);\n                Action<object, object> set = null;\n                if ( prop.CanWrite && prop.GetSetMethod(false) != null )\n                    set = (obj, value) => prop.SetValue(obj, value, EmptyObjectArray);\n                RegisterMember(type, prop, prop.PropertyType, get, set);\n            }","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/YamlSerializer/ObjectMemberAccessor.cs#L28-L64","documentation":"ObjectMemberAccessor's private constructor builds a reflection-based accessor for a type. The check that rejects non-public types is commented out in this vendored copy, so under the original logic ArgumentException('Can not serialize non-public type {0}.') fires when the constructor is given an internal/private type for YAML serialization. The snippet shown is the source region where that guard would execute.","triggerScenarios":"Constructing an ObjectMemberAccessor (via the YAML serializer) for a type not visible to the serializer — internal/private classes, or public types in unsigned assemblies without InternalsVisibleTo being reflected over.","commonSituations":"Serializing internal config/model classes; types marked internal in libraries; generic types instantiated with internal type arguments.","solutions":["Make the type public (or the relevant members public) so the serializer can reflect it.","Use [YamlSerializable]-compatible public DTOs as an intermediary and map from internal types.","If you control the vendored serializer, note the guard is commented out — non-public types now pass through but may fail later on member access.","Add InternalsVisibleTo if the serializer runs in a friend assembly context."],"exampleFix":"// before\ninternal class Config { public string Name; } // serializer may reject\n// after\npublic class Config { public string Name; }","handlingStrategy":"type-guard","validationCode":"if (type != null && !type.IsPublic && !type.IsNestedPublic) throw new ArgumentException(type.FullName + \" must be public for YAML serialization\");","typeGuard":"static bool IsYamlSerializable(Type t) => t.IsPublic || t.IsNestedPublic;","tryCatchPattern":"try { serializer.Serialize(writer, obj); } catch (ArgumentException ex) when (ex.Message.Contains(\"non-public\")) { mapToPublicDtoAndRetry(); }","preventionTips":["Keep serialized DTO types public","Add a reflection smoke test that accesses all serializable types","Avoid serializing internal domain types directly"],"tags":["csharp","yaml","serialization","reflection"],"backgroundTag":"non-serializable-type","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}