Unity-Technologies/UnityCsReference · error · Exception

Invalid EvalDataParcel data for external code execution.

Error message

Invalid EvalDataParcel data for external code execution.

What it means

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.

Source

Thrown at Editor/Mono/Macros/MethodEvaluator.cs:171

        }

        public static object ExecuteExternalCode(string parcel)
        {
            EvalDataParcel evalDataParcel;
            // Process EvalDataParcel to extract known types information which is required for
            // deserialization of the main EvalRemoteMethodCallParcel data.
            using (var dataStream = new MemoryStream(Convert.FromBase64String(parcel)))
            {
                // Setting quotas to max to avoid issues with large data.
                using var reader = XmlDictionaryReader.CreateTextReader(dataStream, XmlDictionaryReaderQuotas.Max);
                var serializer = new DataContractSerializer(typeof(EvalDataParcel));
                try
                {
                    evalDataParcel = (EvalDataParcel)serializer.ReadObject(reader, true);
                }
                catch (SerializationException)
                {
                    throw new Exception("Invalid EvalDataParcel data for external code execution.");
                }
            }

            // Prepare list of known types information. Add EnumSurrogate to support int to enum remapping.
            var knownTypeNames = new List<Type>() { typeof(MethodEvaluatorSurrogateProvider.EnumSurrogate) };
            for (var i = 0; i < evalDataParcel.KnownTypeNames.Length; ++i)
            {
                // Avoid loading assemblies which are already loaded - empty path means that this type is in system assembly.
                if (!string.IsNullOrEmpty(evalDataParcel.KnownTypeAssemblyPaths[i]) && File.Exists(evalDataParcel.KnownTypeAssemblyPaths[i]))
                    CurrentAssemblies.LoadFromPath(evalDataParcel.KnownTypeAssemblyPaths[i]);

                var type = Type.GetType(evalDataParcel.KnownTypeNames[i]);
                if (type == null)
                {
                    throw new Exception($"Invalid EvalDataParcel. Could not find type {evalDataParcel.KnownTypeNames[i]} in for external code execution arguments.");
                }
                knownTypeNames.Add(type);
            }

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Regenerate the parcel from a fresh serialization of a valid EvalDataParcel using the current evaluator.
  2. Verify the parcel string is intact (no truncation/encoding changes) before invoking ExecuteExternalCode.
  3. Ensure producer and consumer run the same Unity/editor build so the DataContract schema matches.
Defensive patterns

Strategy: try-catch

Validate before calling

// Regenerate the parcel via a fresh DataContractSerializer.Serialize of a valid EvalDataParcel before calling ExecuteExternalCode.

Try / catch

try { ExecuteExternalCode(parcel); }
catch (Exception ex) when (ex.Message.Contains("Invalid EvalDataParcel data")) { Debug.LogError($"Malformed/parcel version mismatch: regenerate it."); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/395241f4eadf3bef. Report an issue: GitHub.