{"record":{"id":"395241f4eadf3bef","repo":"Unity-Technologies/UnityCsReference","slug":"invalid-evaldataparcel-data-for-external-code-exec","errorCode":null,"errorMessage":"Invalid EvalDataParcel data for external code execution.","messagePattern":"Invalid EvalDataParcel data for external code execution\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Macros/MethodEvaluator.cs","lineNumber":171,"sourceCode":"        }\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)\n                {\n                    throw new Exception(\"Invalid EvalDataParcel data for external code execution.\");\n                }\n            }\n\n            // Prepare list of known types information. Add EnumSurrogate to support int to enum remapping.\n            var knownTypeNames = new List<Type>() { typeof(MethodEvaluatorSurrogateProvider.EnumSurrogate) };\n            for (var i = 0; i < evalDataParcel.KnownTypeNames.Length; ++i)\n            {\n                // Avoid loading assemblies which are already loaded - empty path means that this type is in system assembly.\n                if (!string.IsNullOrEmpty(evalDataParcel.KnownTypeAssemblyPaths[i]) && File.Exists(evalDataParcel.KnownTypeAssemblyPaths[i]))\n                    CurrentAssemblies.LoadFromPath(evalDataParcel.KnownTypeAssemblyPaths[i]);\n\n                var type = Type.GetType(evalDataParcel.KnownTypeNames[i]);\n                if (type == null)\n                {\n                    throw new Exception($\"Invalid EvalDataParcel. Could not find type {evalDataParcel.KnownTypeNames[i]} in for external code execution arguments.\");\n                }\n                knownTypeNames.Add(type);\n            }","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Macros/MethodEvaluator.cs#L153-L189","documentation":"Thrown by ExecuteExternalCode when deserializing the base64 parcel into an EvalDataParcel fails with a SerializationException. The original exception is caught and rethrown as a generic Exception with a clearer message, since the parcel data is malformed or incompatible.","triggerScenarios":"Passing a parcel string that is not valid base64, that decodes to data the DataContractSerializer cannot read as an EvalDataParcel, or that was produced by a version with a different EvalDataParcel contract.","commonSituations":"Hand-constructed or stale parcel payloads. A macro/eval round-trip across Unity versions where the EvalDataParcel schema changed. Truncation of the base64 string in transport or logging.","solutions":["Regenerate the parcel from a fresh serialization of a valid EvalDataParcel using the current evaluator.","Verify the parcel string is intact (no truncation/encoding changes) before invoking ExecuteExternalCode.","Ensure producer and consumer run the same Unity/editor build so the DataContract schema matches."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Regenerate the parcel via a fresh DataContractSerializer.Serialize of a valid EvalDataParcel before calling ExecuteExternalCode.","typeGuard":null,"tryCatchPattern":"try { ExecuteExternalCode(parcel); }\ncatch (Exception ex) when (ex.Message.Contains(\"Invalid EvalDataParcel data\")) { Debug.LogError($\"Malformed/parcel version mismatch: regenerate it.\"); }","preventionTips":["Regenerate parcels with current evaluator","Keep base64 intact in transit","Align producer and consumer Unity versions"],"tags":["unity","editor","macros","serialization","datacontract","external-code"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}