stride3d/stride · error · OptionException
Unexpected arguments
Error message
Unexpected arguments [{0}] What it means
The ObjectReference constructor validates that objectValue is an instance of objectType; passing a non-null value whose runtime type does not match (or derive from) the declared type throws ArgumentException for objectValue. This keeps every reference's stored object consistent with its declared Type.
Solutions
- Ensure objectType matches the runtime type of objectValue (or a base type/interface of it).
- Refresh type metadata after model refactors so declared types track actual object types.
- Guard creation with objectType.IsInstanceOfType(objectValue) before constructing the reference.
Example fix
// before new ObjectReference(value, typeof(OldModel), index); // value is NewModel // after new ObjectReference(value, value.GetType(), index);
Defensive patterns
Strategy: type-guard
Validate before calling
if (objectValue != null && !objectType.IsInstanceOfType(objectValue))
throw new ArgumentException($"{objectValue.GetType()} is not {objectType}", nameof(objectValue)); Type guard
bool MatchesDeclaredType(object? value, Type declared) => value == null || declared.IsInstanceOfType(value);
Try / catch
try { var rf = CreateReference(value, declaredType, index); }
catch (ArgumentException ex) when (ex.ParamName == "objectValue") { /* recreate with value.GetType() or refresh type metadata */ } Prevention
- Derive objectType from value.GetType() when the value exists
- Refresh cached type metadata after model refactors
- Unit-test reference creation across serialized model types
When it happens
Trigger: Constructing ObjectReference (internal, via reference-building code) with a value whose runtime type differs from objectType, e.g. passing a DerivedModel while declaring typeof(OtherModel), or a stale object after a type refactor.
Common situations: Serialization/deserialization mismatches where a node's content type changed but cached type metadata did not; refactors renaming/moving model classes leaving old values in place; generic helper code passing object-typed values with an unrelated declared type.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- This tool requires a build path.
- The index must be an int.
- The index must be an int.
- The parameter of the ConvertBack method of this converter…
- obj is not the same type as this instance.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/7c13ef5fab2cab49.
Report an issue: GitHub.
Appendix: source
Thrown at sources/assets/Stride.AssetCompiler/PackageBuilderApp.cs:405
if (sessionResult.Session == null)
return (int)BuildResultCode.BuildError;
// Be lenient like Game Studio: load errors (e.g. a project that won't build against the new
// version, so its script-referencing assets load as IUnloadable) don't abort the upgrade.
// Reconcile and save whatever loaded — IUnloadable round-trips its original YAML, so nothing
// is lost — and let the exit code below still report the errors.
if (sessionResult.HasErrors)
options.Logger.Warning("The session loaded with errors; upgrading and saving the assets that loaded. Fix the errors and re-run for a complete upgrade.");
ReconcileBases(sessionResult.Session, options.Logger);
sessionResult.Session.Save(options.Logger);
return (int)(options.Logger.HasErrors ? BuildResultCode.BuildError : BuildResultCode.Successful);
}
if (unexpectedArgs.Any())
{
throw new OptionException("Unexpected arguments [{0}]".ToFormat(string.Join(", ", unexpectedArgs)), "args");
}
try
{
options.ValidateOptions();
}
catch (ArgumentException ex)
{
throw new OptionException(ex.Message, ex.ParamName);
}
if (mode == BuilderMode.Pack)
{
PackageSessionPublicHelper.FindAndSetMSBuildVersion();
var csprojFile = options.PackageFile;
var intermediatePackagePath = options.BuildDirectory;
var generatedItems = new List<(string SourcePath, string PackagePath)>();
var logger = new LoggerResult();View on GitHub (pinned to 96fad776d2)