{"record":{"id":"a663cd7c94db8dc8","repo":"stride3d/stride","slug":"shadowobject-is-not-enabled-you-need-to-enable-it-in-order","errorCode":null,"errorMessage":"ShadowObject is not enabled. You need to enable it in order to use this method. Note also that ShadowObject has a performance cost at runtime","messagePattern":"ShadowObject is not enabled\\. You need to enable it in order to use this method\\. Note also that ShadowObject has a performance cost at runtime","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Design/Reflection/ShadowObject.cs","lineNumber":64,"sourceCode":"    /// <returns>The shadow instance or <c>null</c> if none</returns>\n    public static ShadowObject? Get(object? instance)\n    {\n        if (!Enable || instance == null) return null;\n        Shadows.TryGetValue(instance, out var shadow);\n        return shadow;\n    }\n\n    /// <summary>\n    /// Gets the <see cref=\"ShadowObject\"/> instance. Creates it if it does not exist.\n    /// </summary>\n    /// <param name=\"instance\">The live instance.</param>\n    /// <returns>The shadow instance</returns>\n    [return: NotNullIfNotNull(nameof(instance))]\n    public static ShadowObject? GetOrCreate(object? instance)\n    {\n        if (!Enable)\n        {\n            throw new InvalidOperationException(\"ShadowObject is not enabled. You need to enable it in order to use this method. Note also that ShadowObject has a performance cost at runtime\");\n        }\n\n        if (instance == null) return null;\n        return Shadows.GetValue(instance, _ => new ShadowObject());\n    }\n\n    /// <summary>\n    /// Copies all dynamic properties from an instance to another instance.\n    /// </summary>\n    /// <param name=\"fromInstance\">The instance to copy the shadow attributes from</param>\n    /// <param name=\"toInstance\">The instance to copy the shadow attributes to</param>\n    public static void Copy(object fromInstance, object toInstance)\n    {\n        if (!Enable) return;\n#if NET6_0_OR_GREATER\n        ArgumentNullException.ThrowIfNull(fromInstance);\n        ArgumentNullException.ThrowIfNull(toInstance);\n#else","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Design/Reflection/ShadowObject.cs#L46-L82","documentation":"ShadowObject is an opt-in debugging/reflection feature whose per-instance shadow dictionaries add runtime overhead, so it is disabled by default via ShadowObject.Enable. GetOrCreate() throws InvalidOperationException when the feature has not been enabled, protecting users from silently paying the performance cost.","triggerScenarios":"Calling ShadowObject.GetOrCreate(instance) without first setting ShadowObject.Enable = true.","commonSituations":"Using debugger visualizers or design-time tools that rely on ShadowObject in a host process where no one enabled it; writing diagnostics code copied from a sample that had a static initializer enabling the flag.","solutions":["Set ShadowObject.Enable = true before calling GetOrCreate","Guard the call site: only call GetOrCreate when ShadowObject.Enable is true","Remove the ShadowObject usage if the runtime performance cost is not acceptable in production code"],"exampleFix":"// before\nvar shadow = ShadowObject.GetOrCreate(myObject);\n// after\nShadowObject.Enable = true;\nvar shadow = ShadowObject.GetOrCreate(myObject);","handlingStrategy":"validation","validationCode":"if (!ShadowObject.Enable)\n    throw new InvalidOperationException(\"Enable ShadowObject before calling GetOrCreate\");","typeGuard":null,"tryCatchPattern":"try { var shadow = ShadowObject.GetOrCreate(obj); }\ncatch (InvalidOperationException) { /* feature disabled: skip shadow logic */ }","preventionTips":["Enable ShadowObject once at application startup before any reflection tooling runs","Avoid ShadowObject in production hot paths due to runtime cost","Centralize GetOrCreate access behind a helper that checks Enable"],"tags":["reflection","debugging","invalid-state"],"backgroundTag":"feature-not-enabled","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"}