(Case 1155383) Exception thrown while invoking [OnOpenAssetAttribute]

Right-clicking in the Project window provides the ability to “Open” always. Clicking the “Open” context-menu button, while no asset is selected, displays an ArgumentOutOfRangeException.

ArgumentOutOfRangeException: startIndex cannot be larger than length of string.```

Video

[spoiler]

https://www.youtube.com/watch?v=gnR-ekTo1LU

[/spoiler]

**Reproduce**

- Open attached project or create a new one

- Right-click in the Project window while no asset is selected
- Choose "Open" from the context-menu

**Actual**
Unity outputs an ArgumentOutOfRangeException exception.

**Expected**
The "Open" button should be disabled if there is no selection.
1 Like

workaround:-
open Preferences, to External Tools and reselect Visual Studio from the dropdown menu, it should resolve the problem.

3 Likes

This issue was fixed in a4: Unity Issue Tracker - ArgumentOutOfRangeException is thrown when Assets folder is selected when Project Browser in One Column Layout

1 Like

still workaround need for a unity 2020.1.2f1

same here 2020.1.9f1 , I can’t open visual studio c# script from unity.

it happen again 2020.2.1f1, 2.2f1, if open script within unity, then syntaxtree error occurs and VS-Unity not connected each other.

And still in 2021.1.12f1

And still in 2021.1.13f1

have someone fixed this problem?

Had the same error and this worked:
Exit the unity, delete all auto-generated csproj and sln files from the root folder of the game, open the project again and generate them thru Preferences->External Tools->Regenerate project files.

1 Like