Unity-Technologies/UnityCsReference · error · ArgumentException

GetInstallationForPath: Does not allow null editorPath

Error message

GetInstallationForPath: Does not allow null editorPath

What it means

ArgumentException thrown by CodeEditor.GetInstallationForPath when editorPath is null. The method must look up the IExternalCodeEditor installation for a path (including the SystemDefaultPath special case), so a null path is rejected up front before any editor iteration.

Source

Thrown at Editor/Mono/CodeEditor/CodeEditor.cs:115

            if (string.IsNullOrEmpty(assetPath))
            {
                return false;
            }

            var assetFilePath = Path.GetFullPath(assetPath);
            var didOpenProject = Editor.CurrentCodeEditor.OpenProject(assetFilePath, line, column);
            if (didOpenProject)
            {
                CodeEditorAnalytics.SendCodeEditorUsage(CodeEditor.Editor.CurrentCodeEditor);
            }
            return didOpenProject;
        }

        public Installation GetInstallationForPath(string editorPath)
        {
            if (editorPath == null)
            {
                throw new ArgumentException("GetInstallationForPath: Does not allow null editorPath");
            }

            Installation installation;
            if (editorPath == CodeEditor.SystemDefaultPath)
            {
                m_DefaultEditor.TryGetInstallationForPath(editorPath, out installation);
                return installation;
            }

            foreach (var codeEditor in m_ExternalCodeEditors)
            {
                if (codeEditor.TryGetInstallationForPath(editorPath, out installation))
                {
                    return installation;
                }
            }
            m_DefaultEditor.TryGetInstallationForPath(editorPath, out installation);
            return installation;

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Validate editorPath is non-null (and ideally non-empty/file-present) before calling GetInstallationForPath.
  2. Fall back to CodeEditor.SystemDefaultPath when the detected path is null.
  3. Ensure EditorPrefs for the script editor are set (Editor.SetCodeEditor) before querying installations.

Example fix

// before
var install = CodeEditor.GetInstallationForPath(detectedPath);

// after
var path = detectedPath ?? CodeEditor.SystemDefaultPath;
var install = CodeEditor.GetInstallationForPath(path);
Defensive patterns

Strategy: validation

Validate before calling

if (editorPath == null) editorPath = CodeEditor.SystemDefaultPath;
var install = CodeEditor.GetInstallationForPath(editorPath);

Prevention

When it happens

Trigger: Calling CodeEditor.GetInstallationForPath(null). Common when the editor path is read from EditorPrefs/project settings that are unset, or passed through from a caller that did not validate a user-selected script editor path.

Common situations: First-run scenarios where the external script editor preference ('kScriptsDefaultApp') has not been set; tooling that resolves the editor path from an environment variable or detection routine that can return null.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/b0d283715534395a. Report an issue: GitHub.