{"record":{"id":"40c1de2ac09b3ca2","repo":"peass-ng/PEASS-ng","slug":"illegal-object-in-getinstance-40c1de","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/DerBmpString.cs","lineNumber":28,"sourceCode":"        : DerStringBase\n    {\n        private readonly string str;\n\n        /**\n         * return a BMP string from the given object.\n         *\n         * @param obj the object we want converted.\n         * @exception ArgumentException if the object cannot be converted.\n         */\n        public static DerBmpString GetInstance(\n            object obj)\n        {\n            if (obj == null || obj is DerBmpString)\n            {\n                return (DerBmpString)obj;\n            }\n\n            throw new ArgumentException(\"illegal object in GetInstance: \" + Platform.GetTypeName(obj));\n        }\n\n        /**\n         * return a BMP string 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 DerBmpString GetInstance(\n            Asn1TaggedObject obj,\n            bool isExplicit)\n        {\n            Asn1Object o = obj.GetObject();\n\n            if (isExplicit || o is DerBmpString)","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerBmpString.cs#L10-L46","documentation":"DerBmpString.GetInstance(object) only accepts null or an actual DerBmpString instance; any other object type causes ArgumentException with 'illegal object in GetInstance'. This is BouncyCastle's standard type-assertion pattern for ASN.1 string conversions.","triggerScenarios":"Calling DerBmpString.GetInstance(obj) where obj is a DerUtf8String, DerPrintableString, DerOctetString, Asn1Sequence, byte[], or any other non-DerBmpString ASN.1 object — commonly after reading an untyped Asn1Object from a tag.","commonSituations":"Parsing certificates with a generic GetInstance on an explicitly tagged value without specifying the expected type; assuming a string-typed ASN.1 field is BMPString when it is UTF8String or PrintableString.","solutions":["Call DerBmpString.GetInstance(obj, false) / GetInstance(asn1TaggedObject, false) only when the encoded type is truly BMPString ( UniversalString tag 30).","Use the explicit-type overload GetInstance(Asn1TaggedObject, bool explicitly, Type) or check obj is DerBmpString first.","If the type can vary, convert via Asn1Object.GetInstance and branch on the concrete type, or use the string's Getstring()."],"exampleFix":"// before\nvar s = DerBmpString.GetInstance(taggedObj.GetObject()); // may be another string type\n// after\nif (obj is DerBmpString bmp) { /* use bmp */ }\nelse if (obj is DerUtf8String u) { /* handle utf8 */ }\nelse throw new InvalidDataException(\"unexpected ASN.1 string type: \" + obj.GetType());","handlingStrategy":"type-guard","validationCode":"if (!(obj is DerBmpString)) { /* it is another ASN.1 type — branch accordingly */ }","typeGuard":"static bool IsBmpString(object o) => o is DerBmpString;","tryCatchPattern":"try { var s = DerBmpString.GetInstance(obj); }\ncatch (ArgumentException) { /* obj was a different ASN.1 type: inspect obj.GetType() */ }","preventionTips":["Know the expected ASN.1 tag of each field before choosing the GetInstance type","Use pattern matching (obj is DerBmpString s) before conversion","For tagged objects, use the explicit-type GetInstance overload"],"tags":["csharp","asn1","type-mismatch","bouncycastle","getinstance"],"backgroundTag":"illegal-asn1-object-type","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}