I have a unity project I’m working on but I’m having trouble using Visual Studio 2017 for scripting. Monodevelop seems to work fine though but I would rather use Visual Studio. It’s only this one project which has this error as I can use Visual Studio 2017 fine on any other project.
Whenever I try to open a script or use Assets->Open C# Project I get this error in the console (pasted below) in the console and no sln or cproj files are created.
Error:
ArgumentException: Value does not fall within the expected range.
SyntaxTree.VisualStudio.Unity.Bridge.CompilationUnit.LanguageOf (SyntaxTree.VisualStudio.Unity.Bridge.CompilationUnit unit)
SyntaxTree.VisualStudio.Unity.Bridge.CompilationUnit.CompilationUnits (System.String method)
SyntaxTree.VisualStudio.Unity.Bridge.CompilationUnit.CompilationUnits ()
SyntaxTree.VisualStudio.Unity.Bridge.ProjectSystem.UnitySolutionBuilder…ctor ()
SyntaxTree.VisualStudio.Unity.Bridge.ProjectSystem.UnitySolutionBuilder.CreateSolutionFromAssetDatabase ()
SyntaxTree.VisualStudio.Unity.Bridge.ProjectFilesGenerator.GenerateProject ()
SyntaxTree.VisualStudio.Unity.Bridge.ProjectFilePostprocessor.OnPreGeneratingCSProjectFiles ()
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[ ] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[ ] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[ ] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.AssetPostprocessingInternal.OnPreGeneratingCSProjectFiles () (at C:/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:61)
UnityEditor.VisualStudioIntegration.SolutionSynchronizer.Sync () (at C:/buildslave/unity/build/Editor/Mono/VisualStudioIntegration/SolutionSynchronizer.cs:189)
UnityEditor.SyncVS.CreateIfDoesntExist () (at C:/buildslave/unity/build/Editor/Mono/SyncProject.cs:147)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
Updating Visual Studio to 15.5.5 seems to have solved the problem. For anyone else having this problem, go to Tools->Extensions and Updates and then under Updates you’ll have the update if you are on an older version,
The VS update (>= 15.5.5) helped me as well. Though you need to fix all compiler errors before you can open your projects via assets-> open c# project.
I had to update to Visual studio 15.7.3 after a Windows upgrade (that broke other software, too,) AND a Unity upgrade. Not sure which did what, but it’s going again. (The windows upgrade was for GDPR compliance, I’m pretty sure, so I’ll blame it on that. HA!)
I’m still getting this issue with Unity 2018.1 and VS 2017 15.7.4. Also I don’t see “Visual Studio” in the list of External Editors in the Unity Preferences; it’s set to “internal”, which works when I double-click a .cs file.
As others in this thread suggest, an update of Visual Studio resolved the issue for me as well.
Old version: 15.0.26430.16
New version: 15.7.27703.2042
@trojanfoe it’s odd that Visual Studio 2017 is not listed for you…
Maybe try to manually specify the application? Unity Preferences → External Tools → External Script Editor → Browse… then look for
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe