{"record":{"id":"1c7b8c17b2b972b9","repo":"Unity-Technologies/UnityCsReference","slug":"incorrect-file-extension-prefabassetpath-must","errorCode":null,"errorMessage":"Incorrect file extension: {prefabAssetPath}. Must be '.prefab'","messagePattern":"Incorrect file extension: (.+?)\\. Must be '\\.prefab'","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/SceneManagement/StageManager/PrefabStage/PrefabStageUtility.cs","lineNumber":96,"sourceCode":"            var prefabStageMode = openedFromInstance != null ? PrefabStage.Mode.InContext : PrefabStage.Mode.InIsolation;\n            return OpenPrefab(prefabAssetPath, openedFromInstance, prefabStageMode, changeTypeAnalytics);\n        }\n\n        public static PrefabStage OpenPrefab(string prefabAssetPath, GameObject openedFromInstance, PrefabStage.Mode prefabStageMode)\n        {\n            return OpenPrefab(prefabAssetPath, openedFromInstance, prefabStageMode, StageNavigationManager.Analytics.ChangeType.EnterViaUnknown);\n        }\n\n        internal static PrefabStage OpenPrefab(string prefabAssetPath, GameObject openedFromInstance, PrefabStage.Mode prefabStageMode, StageNavigationManager.Analytics.ChangeType changeTypeAnalytics)\n        {\n            if (string.IsNullOrEmpty(prefabAssetPath))\n                throw new ArgumentNullException(nameof(prefabAssetPath));\n\n            if (openedFromInstance != null && !PrefabUtility.IsPartOfPrefabInstance(openedFromInstance))\n                throw new ArgumentException(\"GameObject must be part of a Prefab instance, or null.\", nameof(openedFromInstance));\n\n            if (!prefabAssetPath.EndsWith(\".prefab\", StringComparison.OrdinalIgnoreCase))\n                throw new ArgumentException(\"Incorrect file extension: \" + prefabAssetPath + \". Must be '.prefab'\", nameof(prefabAssetPath));\n\n            if (AssetDatabase.LoadMainAssetAtPath(prefabAssetPath) == null)\n                throw new ArgumentException(\"Prefab not found at path \" + prefabAssetPath, nameof(prefabAssetPath));\n\n            return OpenPrefabMode(prefabAssetPath, openedFromInstance, prefabStageMode, changeTypeAnalytics);\n        }\n\n        static PrefabStage GetExistingPrefabStage(string prefabAssetPath, GameObject openedFromInstance, PrefabStage.Mode prefabStageMode)\n        {\n            var stageHistory = StageNavigationManager.instance.stageHistory;\n            for (int i = 1; i < stageHistory.Count; i++)\n            {\n                var prefabStage = stageHistory[i] as PrefabStage;\n                if (prefabStage != null && prefabStage.assetPath == prefabAssetPath)\n                {\n                    // If PrefabStage.Mode did not match on existing PrefabStage we do not reuse the stage\n                    // so we create a new PrefabStage with the correct mode\n                    if (prefabStage.mode == prefabStageMode)","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/SceneManagement/StageManager/PrefabStage/PrefabStageUtility.cs#L78-L114","documentation":"Thrown by PrefabStageUtility.OpenPrefab when prefabAssetPath does not end with '.prefab' (case-insensitive). The prefab system only operates on assets with the .prefab extension; any other extension is rejected at the validation boundary.","triggerScenarios":"Passing a path with .prefabVariant, .asset, .mat, or no extension. Typo in the path extension. Constructed paths that drop the extension during string manipulation.","commonSituations":"Path built via Path.GetFileNameWithoutExtension without re-appending '.prefab'. Mixing up prefab asset paths with ScriptableObject '.asset' paths. Cross-platform path separators causing the EndsWith check to miss.","solutions":["Ensure the path string ends with '.prefab' (case-insensitive).","Construct paths using Path.Combine and explicitly append '.prefab'.","Validate with prefabAssetPath.EndsWith(\".prefab\", StringComparison.OrdinalIgnoreCase) before calling."],"exampleFix":"// before\nPrefabStageUtility.OpenPrefab(\"Assets/MyObject\", null, mode);\n\n// after\nPrefabStageUtility.OpenPrefab(\"Assets/MyObject.prefab\", null, mode);","handlingStrategy":"validation","validationCode":"bool IsValidPrefabPath(string path)\n{\n    return !string.IsNullOrEmpty(path) && path.EndsWith(\".prefab\", StringComparison.OrdinalIgnoreCase);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always build prefab asset paths with an explicit '.prefab' suffix.","Use Path.Combine and append '.prefab' rather than relying on string concatenation."],"tags":["unity","prefab","editor","validation","path"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}