{"record":{"id":"9f1e82a2535f41be","repo":"Unity-Technologies/UnityCsReference","slug":"expected-o-to-be-a-string-or-a-type-it-is-a-o","errorCode":null,"errorMessage":"Expected {o} to be a string or a Type. It is a {o.GetType()}","messagePattern":"Expected (.+?) to be a string or a Type\\. It is a (.+?)","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Macros/MethodEvaluator.cs","lineNumber":137,"sourceCode":"                null, paramTypes, null);\n            if (method == null)\n                throw new ArgumentException(string.Format(\n                    \"Method {0}.{1}({2}) not found in assembly {3}!\", typeName,\n                    methodName, ToCommaSeparatedString(paramTypes),\n                    assembly.FullName));\n            return method.Invoke(null, args);\n        }\n\n        private static Type TypeOrTypeName(object o)\n        {\n            switch (o)\n            {\n                case Type t:\n                    return t;\n                case string s:\n                    return Type.GetType(s);\n                default:\n                    throw new FormatException($\"Expected {o} to be a string or a Type. It is a {o.GetType()}\");\n            }\n        }\n\n        private static Type[] TypesOrTypeNames(object o)\n        {\n\n            switch (o)\n            {\n                case Type[] t:\n                    return t;\n                case string[] s:\n                    return Array.ConvertAll(s, Type.GetType);\n                default:\n                    throw new FormatException($\"Expected {o} to be a string[] or a Type[]. It is a {o.GetType()}\");\n            }\n        }\n\n        public static object ExecuteExternalCode(string parcel)","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Macros/MethodEvaluator.cs#L119-L155","documentation":"Thrown by the private TypeOrTypeName helper when its input is neither a Type nor a string. The helper coerces an object into a Type for the macro evaluator's known-type resolution; any other runtime type falls through to a FormatException.","triggerScenarios":"An EvalDataParcel known-types payload contains an element that deserializes to a type other than Type or string (e.g. an int, an enum, or a custom serialized object). Corrupted or version-mismatched eval parcel data.","commonSituations":"External code execution (ExecuteExternalCode) invoked with a base64 parcel whose known-type entries were serialized by an incompatible Unity/tooling version, producing unexpected element types after deserialization.","solutions":["Regenerate the eval data parcel with the current evaluator so known-type entries are Type or string.","Ensure the parcel is produced and consumed by the same Unity/editor version to avoid deserialization drift.","Validate each known-type entry is a Type or string before invoking ExecuteExternalCode."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"if (!(o is Type) && !(o is string)) throw new FormatException($\"Expected Type or string, got {o?.GetType()}\");","typeGuard":"static bool IsTypeOrTypeName(object o) => o is Type || o is string;","tryCatchPattern":"try { /* evaluator call */ }\ncatch (FormatException ex) when (ex.Message.Contains(\"string or a Type\")) { Debug.LogError($\"Bad known-type entry: {ex.Message}\"); }","preventionTips":["Regenerate eval parcels with current versions","Validate known-type entries are Type or string","Keep producer and consumer versions aligned"],"tags":["unity","editor","macros","reflection","serialization","type-resolution"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}