{"record":{"id":"3cdfcb940c9e7636","repo":"stride3d/stride","slug":"cannot-register-new-platforms-registersupportedplatforms-can","errorCode":null,"errorMessage":"Cannot register new platforms. RegisterSupportedPlatforms can only be called once","messagePattern":"Cannot register new platforms\\. RegisterSupportedPlatforms can only be called once","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/AssetRegistry.cs","lineNumber":76,"sourceCode":"    /// </summary>\n    /// <value>The supported platforms.</value>\n    public static SolutionPlatformCollection SupportedPlatforms { get; }\n\n    /// <summary>\n    /// Gets an enumeration of registered importers.\n    /// </summary>\n    /// <value>The registered importers.</value>\n    public static IEnumerable<IAssetImporter> RegisteredImporters { get { lock (RegistryLock) { return RegisteredImportersInternal; } } }\n\n    /// <summary>\n    /// Registers the supported platforms.\n    /// </summary>\n    /// <param name=\"platforms\">The platforms.</param>\n    /// <exception cref=\"System.ArgumentNullException\">platforms</exception>\n    public static void RegisterSupportedPlatforms(List<SolutionPlatform> platforms)\n    {\n        ArgumentNullException.ThrowIfNull(platforms);\n        if (SupportedPlatforms.Count > 0) throw new InvalidOperationException(\"Cannot register new platforms. RegisterSupportedPlatforms can only be called once\");\n        SupportedPlatforms.AddRange(platforms);\n    }\n\n    /// <summary>\n    /// Determines whether the file is an asset file type.\n    /// </summary>\n    /// <param name=\"extension\">The file.</param>\n    /// <returns><c>true</c> if [is asset file file] [the specified file]; otherwise, <c>false</c>.</returns>\n    public static bool IsAssetFileExtension(string? extension)\n    {\n        if (extension == null) return false;\n        lock (RegistryLock)\n        {\n            return RegisteredAssetFileExtensions.ContainsKey(extension);\n        }\n    }\n\n    /// <summary>","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/AssetRegistry.cs#L58-L94","documentation":"AssetRegistry.RegisterSupportedPlatforms throws InvalidOperationException if SupportedPlatforms has already been populated. Platform support is a process-wide, write-once static configuration: mixing registration calls would produce ambiguous platform sets.","triggerScenarios":"Calling AssetRegistry.RegisterSupportedPlatforms a second time in the same process, e.g. from both a plugin and the host app, or in a repeated test setup without clearing state.","commonSituations":"Two modules each initializing the asset system at startup; unit tests re-registering platforms per fixture because static state persists between tests.","solutions":["Guard the call: only register when AssetRegistry.SupportedPlatforms.Count == 0.","Move registration to a single central bootstrap point and have other modules read the existing value.","In tests, register once in a one-time setup (or check the guard before each registration)."],"exampleFix":"// before\nAssetRegistry.RegisterSupportedPlatforms(platforms);\n// after\nif (AssetRegistry.SupportedPlatforms.Count == 0)\n    AssetRegistry.RegisterSupportedPlatforms(platforms);","handlingStrategy":"validation","validationCode":"if (AssetRegistry.SupportedPlatforms.Count > 0) return; // already registered\nAssetRegistry.RegisterSupportedPlatforms(platforms);","typeGuard":null,"tryCatchPattern":"try { AssetRegistry.RegisterSupportedPlatforms(platforms); } catch (InvalidOperationException) { /* already registered - ignore */ }","preventionTips":["Register platforms exactly once in a single bootstrap method.","Use a Lazy<T>/Singleton for asset-system initialization.","In tests, register in [OneTimeSetUp]/static setup, not per-test."],"tags":["assets","static-state","initialization"],"backgroundTag":"invalid-state-transition","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"}