{"record":{"id":"de31b4ae7aa31acd","repo":"stride3d/stride","slug":"url-must-be-valid-assign-null-instead","errorCode":null,"errorMessage":"Url must be valid, assign null instead","messagePattern":"Url must be valid, assign null instead","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.BepuPhysics/Stride.BepuPhysics/BepuSimulation.cs","lineNumber":89,"sourceCode":"\n    /// <summary>\n    /// The scene associated with this simulation.\n    /// </summary>\n    /// <remarks>\n    /// When this is set, entities spawning inside this scene will be automatically associated with\n    /// this simulation as long as their <see cref=\"CollidableComponent.SimulationSelector\"/> is set to <see cref=\"SceneBasedSimulationSelector\"/>.\n    /// See <see cref=\"SceneBasedSimulationSelector\"/> for more info.\n    /// </remarks>\n    public UrlReference<Scene>? AssociatedScene\n    {\n        get\n        {\n            return _associatedScene;\n        }\n        set\n        {\n            if (value?.IsEmpty == true)\n                throw new ArgumentException(\"Url must be valid, assign null instead\");\n\n            _associatedScene = value;\n        }\n    }\n\n    /// <summary>\n    /// The number of threads the simulation may use.\n    /// </summary>\n    /// <remarks>\n    /// <see cref=\"Dispatcher.MaxDegreeOfParallelism\"/> is the upper bound, -1 will default to that value.\n    /// A value greater than <see cref=\"Dispatcher.MaxDegreeOfParallelism\"/> will further split the work, potentially improving throughput depending on the context and simulation.\n    /// </remarks>\n    [Display(-1, \"Thread Count\")]\n    public int ThreadCount\n    {\n        get;\n        set\n        {","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.BepuPhysics/Stride.BepuPhysics/BepuSimulation.cs#L71-L107","documentation":"BepuSimulation.AssociatedScene setter throws ArgumentException when assigned a UrlReference<Scene> that IsEmpty (default-constructed, pointing to no scene). Because a null assignment legitimately means 'no associated scene', the library forbids an empty URL value and instructs you to assign null instead.","triggerScenarios":"Setting simulation.AssociatedScene = new UrlReference<Scene>() (default struct, no URL) or deserializing an entity whose scene URL field was left empty and then assigning it to the property.","commonSituations":"Wiring a BepuSimulation component in an editor/serializer where the scene picker was never filled in; constructing UrlReference<Scene> from an empty string; copying a component from another entity without the scene reference surviving serialization.","solutions":["Assign null instead of an empty UrlReference<Scene> when you mean 'no scene'","Check value.IsEmpty in your own code before assigning and substitute null","Fill in the scene reference in the editor/Game Studio property so the URL is non-empty","If the value comes from deserialization, validate the source field for null/empty before constructing UrlReference<Scene>"],"exampleFix":"// before\nsimulation.AssociatedScene = new UrlReference<Scene>(\"\", null); // IsEmpty == true\n// after\nsimulation.AssociatedScene = string.IsNullOrEmpty(rawUrl) ? (UrlReference<Scene>?)null : new UrlReference<Scene>(rawUrl);","handlingStrategy":"type-guard","validationCode":"if (sceneUrl is UrlReference<Scene> u && u.IsEmpty)\n    sceneUrl = null; // normalize empty URLs to null before assigning","typeGuard":"bool IsValidSceneRef(UrlReference<Scene>? url) => url is null || !url.Value.IsEmpty;","tryCatchPattern":"try\n{\n    simulation.AssociatedScene = sceneUrl;\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Url must be valid\"))\n{\n    Logger.Warn(\"Empty scene URL assigned; defaulting to null\");\n    simulation.AssociatedScene = null;\n}","preventionTips":["Treat 'no scene' as null, never as a default-constructed UrlReference<Scene>","Validate scene reference fields after deserialization of entities","Fill scene pickers in Game Studio before attaching BepuSimulation components","Write a shared normalizer that maps empty URLs to null across your codebase"],"tags":["physics","bepu","validation","urlreference","stride"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}