{"record":{"id":"39f78b6878e5eaa2","repo":"peass-ng/PEASS-ng","slug":"illegal-object-in-getinstance-39f78b","errorCode":null,"errorMessage":"illegal object in GetInstance: ","messagePattern":"illegal object in GetInstance: ","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerEnumerated.cs","lineNumber":26,"sourceCode":"       : Asn1Object\n    {\n        private readonly byte[] bytes;\n        private readonly int start;\n\n        /**\n         * return an integer from the passed in object\n         *\n         * @exception ArgumentException if the object cannot be converted.\n         */\n        public static DerEnumerated GetInstance(\n            object obj)\n        {\n            if (obj == null || obj is DerEnumerated)\n            {\n                return (DerEnumerated)obj;\n            }\n\n            throw new ArgumentException(\"illegal object in GetInstance: \" + Platform.GetTypeName(obj));\n        }\n\n        /**\n         * return an Enumerated from a tagged object.\n         *\n         * @param obj the tagged object holding the object we want\n         * @param explicitly true if the object is meant to be explicitly\n         *              tagged false otherwise.\n         * @exception ArgumentException if the tagged object cannot\n         *               be converted.\n         */\n        public static DerEnumerated GetInstance(\n            Asn1TaggedObject obj,\n            bool isExplicit)\n        {\n            Asn1Object o = obj.GetObject();\n\n            if (isExplicit || o is DerEnumerated)","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerEnumerated.cs#L8-L44","documentation":"DerEnumerated.GetInstance mirrors DerBoolean.GetInstance: it accepts only null or an existing DerEnumerated instance. Any other object type produces this ArgumentException, with the runtime type name appended, because ASN.1 ENUMERATED cannot be represented by other Der* classes.","triggerScenarios":"Calling DerEnumerated.GetInstance(obj) with a DerInteger, DerSequence, DerOctetString, or any non-DerEnumerated object; parsing an ASN.1 field declared ENUMERATED that arrived encoded as a different type.","commonSituations":"Parsing X.509 extensions, CRL reason codes, or PKCS structures where an ENUMERATED field is unexpectedly an INTEGER (some encoders emit INTEGER for enumerated values); using the wrong GetInstance overload for tagged objects.","solutions":["Use the type named in the exception message, e.g. DerInteger.GetInstance(obj), then convert with new DerEnumerated(intVal) if semantics allow","For tagged objects call GetInstance((Asn1TaggedObject)obj, true)","Confirm the ASN.1 schema marks the field ENUMERATED and the encoder complies","Catch ArgumentException and treat the field as invalid"],"exampleFix":"// before\nvar e = DerEnumerated.GetInstance(asn1Obj);\n// after\nvar e = asn1Obj is DerEnumerated en ? en\n      : asn1Obj is DerInteger i ? new DerEnumerated(i.PositiveValue)\n      : throw new FormatException(\"not an ENUMERATED\");","handlingStrategy":"type-guard","validationCode":"bool ok = obj == null || obj is DerEnumerated;","typeGuard":"bool IsDerEnumerated(object o) => o is DerEnumerated;","tryCatchPattern":"try { var e = DerEnumerated.GetInstance(obj); }\ncatch (ArgumentException ex) { /* inspect type name in ex.Message, handle fallback */ }","preventionTips":["Match GetInstance to the actual ASN.1 type (DerInteger vs DerEnumerated)","Unwrap Asn1TaggedObject before GetInstance","Confirm schema types against the encoder implementation","Add parser tests for wrong-type fields"],"tags":["asn1","bouncycastle","argumentexception","parsing"],"backgroundTag":"asn1-type-mismatch","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}