{"record":{"id":"8815c2da195d6007","repo":"Unity-Technologies/UnityCsReference","slug":"expected-o-to-be-a-string-or-a-type-it-is-a","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":151,"sourceCode":"                    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)\n        {\n            EvalDataParcel evalDataParcel;\n            // Process EvalDataParcel to extract known types information which is required for\n            // deserialization of the main EvalRemoteMethodCallParcel data.\n            using (var dataStream = new MemoryStream(Convert.FromBase64String(parcel)))\n            {\n                // Setting quotas to max to avoid issues with large data.\n                using var reader = XmlDictionaryReader.CreateTextReader(dataStream, XmlDictionaryReaderQuotas.Max);\n                var serializer = new DataContractSerializer(typeof(EvalDataParcel));\n                try\n                {\n                    evalDataParcel = (EvalDataParcel)serializer.ReadObject(reader, true);\n                }\n                catch (SerializationException)","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Macros/MethodEvaluator.cs#L133-L169","documentation":"Thrown by the private TypesOrTypeNames helper when its input is neither a Type[] nor a string[]. It mirrors TypeOrTypeName but for arrays used in parameter-type resolution; any other runtime type produces a FormatException.","triggerScenarios":"A deserialized eval payload element expected to be an array of types resolves to a different shape — a single Type/string instead of an array, an object[], or a list type that does not pattern-match Type[]/string[].","commonSituations":"Version skew between the parcel producer and consumer, or a serialization surrogate that converts the array into a non-matching representation.","solutions":["Regenerate the eval parcel with matching versions so parameter-type arrays serialize as Type[] or string[].","Normalize the input to Type[] before calling the evaluator.","Verify the MethodEvaluatorSurrogateProvider round-trips the array shape correctly."],"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 IsTypeOrTypeNameArray(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 param-types entry: {ex.Message}\"); }","preventionTips":["Regenerate eval parcels with matching versions","Normalize param-type arrays before eval","Verify surrogate round-trips array shape"],"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"}