{"record":{"id":"29aecd3c062a0644","repo":"peass-ng/PEASS-ng","slug":"illegal-object-in-getinstance","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/DerBitString.cs","lineNumber":42,"sourceCode":"            object obj)\n        {\n            if (obj == null || obj is DerBitString)\n            {\n                return (DerBitString)obj;\n            }\n            if (obj is byte[])\n            {\n                try\n                {\n                    return (DerBitString)FromByteArray((byte[])obj);\n                }\n                catch (Exception e)\n                {\n                    throw new ArgumentException(\"encoding error in GetInstance: \" + e.ToString());\n                }\n            }\n\n            throw new ArgumentException(\"illegal object in GetInstance: \" + Platform.GetTypeName(obj));\n        }\n\n        /**\n\t\t * return a Bit string from a tagged object.\n\t\t *\n\t\t * @param obj the tagged object holding the object we want\n\t\t * @param explicitly true if the object is meant to be explicitly\n\t\t *              tagged false otherwise.\n\t\t * @exception ArgumentException if the tagged object cannot\n\t\t *               be converted.\n\t\t */\n        public static DerBitString GetInstance(\n            Asn1TaggedObject obj,\n            bool isExplicit)\n        {\n            Asn1Object o = obj.GetObject();\n\n            if (isExplicit || o is DerBitString)","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerBitString.cs#L24-L60","documentation":"DerBitString.GetInstance throws ArgumentException 'illegal object in GetInstance: <type name>' when the supplied object is neither a DerBitString nor a byte[]/tagged object it can convert — i.e. the wrong ASN.1 type was passed for extraction.","triggerScenarios":"Passing a DerSequence, DerInteger, DerOctetString, or null-like/other Asn1Object to DerBitString.GetInstance expecting it to be a BIT STRING.","commonSituations":"Misreading a certificate/PKCS structure and pulling the wrong field (e.g. signature is a BIT STRING but you pass the AlgorithmIdentifier SEQUENCE); type assumptions after a schema/version change in the parsed structure.","solutions":["Check the actual type: parse with Asn1Object.FromByteArray and verify `is DerBitString` before GetInstance","If the source is an Asn1TaggedObject, use the (Asn1TaggedObject, bool explicitly) overload","Fix the field extraction path so the BIT STRING field is selected (e.g. certificate signature value, not signature algorithm)","If you need arbitrary content as bits, convert the object via its own GetEncoded()/ToAsn1Object first"],"exampleFix":"// before\nDerBitString bits = DerBitString.GetInstance(seqObj); // a SEQUENCE\n// after\nif (seqObj is DerBitString bits) { /* use bits */ }\nelse { throw new InvalidDataException(\"expected BIT STRING, got \" + Platform.GetTypeName(seqObj)); }","handlingStrategy":"type-guard","validationCode":"// parse generically and inspect the concrete type before extracting\nAsn1Object o = Asn1Object.FromByteArray(bytes);\nbool ok = o is DerBitString;","typeGuard":"bool IsBitString(Asn1Object o) => o is DerBitString;","tryCatchPattern":"try { return DerBitString.GetInstance(obj); }\ncatch (ArgumentException ex) { throw new InvalidDataException(\"expected BIT STRING, got: \" + ex.Message, ex); }","preventionTips":["Pattern-match (`is DerBitString`) before GetInstance on generic Asn1Object values","Use the (Asn1TaggedObject, bool) overload for tagged objects","Map the parent structure's fields correctly (e.g. X509 signature BIT STRING position)","Keep ASN.1 schema references at hand when extracting fields"],"tags":["asn1","type-mismatch","argument","bouncycastle"],"backgroundTag":"wrong-asn1-type","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}