{"record":{"id":"b36417a901376d47","repo":"peass-ng/PEASS-ng","slug":"illegal-object-in-getinstance-b36417","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/DerGraphicString.cs","lineNumber":38,"sourceCode":"        {\n            if (obj == null || obj is DerGraphicString)\n            {\n                return (DerGraphicString)obj;\n            }\n\n            if (obj is byte[])\n            {\n                try\n                {\n                    return (DerGraphicString)FromByteArray((byte[])obj);\n                }\n                catch (Exception e)\n                {\n                    throw new ArgumentException(\"encoding error in GetInstance: \" + e.ToString(), \"obj\");\n                }\n            }\n\n            throw new ArgumentException(\"illegal object in GetInstance: \" + Platform.GetTypeName(obj), \"obj\");\n        }\n\n        /**\n         * return a Graphic String from a tagged object.\n         *\n         * @param obj the tagged object holding the object we want\n         * @param explicit true if the object is meant to be explicitly\n         *              tagged false otherwise.\n         * @exception IllegalArgumentException if the tagged object cannot\n         *               be converted.\n         * @return a DerGraphicString instance, or null.\n         */\n        public static DerGraphicString GetInstance(Asn1TaggedObject obj, bool isExplicit)\n        {\n            Asn1Object o = obj.GetObject();\n\n            if (isExplicit || o is DerGraphicString)\n            {","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerGraphicString.cs#L20-L56","documentation":"DerGraphicString.GetInstance() only accepts byte[], DerGraphicString, or an Asn1TaggedObject. If the object is any other type, the library throws an ArgumentException naming the offending runtime type via Platform.GetTypeName(obj). This is a type-mismatch guard, not a data corruption error.","triggerScenarios":"Calling DerGraphicString.GetInstance(object) with an object that is neither byte[], DerGraphicString, nor Asn1TaggedObject (e.g. a DerUtf8String, string, or Asn1Sequence).","commonSituations":"Misreading ASN.1 structure so a different ASN.1 type is passed in; switching between overloads; generic parsing code that assumes all parsed objects are GraphicStrings.","solutions":["Check the object's concrete Asn1Object type before calling GetInstance","Parse via Asn1Object.FromByteArray and pattern-match on the result type","If a tagged object is intended, use the GetInstance(Asn1TaggedObject, bool) overload explicitly","Fix the ASN.1 schema assumption that produced the unexpected type"],"exampleFix":"// before\nvar s = DerGraphicString.GetInstance(parsedObject);\n// after\nvar s = parsedObject as DerGraphicString\n    ?? DerGraphicString.GetInstance(((Asn1TaggedObject)parsedObject).GetObject());","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"DerGraphicString TryAsGraphicString(object o) =>\n    o as DerGraphicString ?? (o is Asn1TaggedObject t ? t.GetObject() as DerGraphicString : null);","tryCatchPattern":"try { var s = DerGraphicString.GetInstance(obj); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"illegal object\")) {\n    throw new InvalidDataException($\"unexpected ASN.1 type: {obj?.GetType().Name}\", ex);\n}","preventionTips":["Inspect parsed ASN.1 object types before casting","Match GetInstance overload to the actual input type","Write unit tests against the real ASN.1 schema"],"tags":["csharp","asn1","bouncycastle","type-mismatch"],"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"}