72

Suddenly I am getting this error "Value does not fall within the expected range" whenever I try to add a reference to any project. This also happens with a new blank project. It can list the current references fine.

I rebooted the computer. I am not sure if the recent Update 2 caused this. This is my first add reference since the update. I am using Visual Studio 2013 on Windows 7 64bit.

Any ideas?

enter image description here

Aristos
  • 66,005
  • 16
  • 114
  • 150
Tony_Henrich
  • 42,411
  • 75
  • 239
  • 374
  • 4
    If you're getting this error, make sure you look in your Output window and flip through the various Build/General dropdown options for Output. I found additional details after the error message, about which tag in my project file was causing the failure, which helped troubleshoot. – AaronLS Feb 21 '20 at 20:50

16 Answers16

82

I did a 'devenv /setup' and that fixed it.

Detail

  • Exit Visual Studio
  • Click Start
  • Type cmd, right click Command Prompt and select Run as administrator
  • Navigate to the appropriate Visual Studio folder
    VS2012: pushd %programfiles(x86)%\Microsoft Visual Studio 12.0\Common7\IDE
    VS2015: pushd %programfiles(x86)%\Microsoft Visual Studio 14.0\Common7\IDE
    VS2017: pushd %programfiles(x86)%\Microsoft Visual Studio\2017\<Edition>\Common7\IDE
    VS2019: pushd %programfiles(x86)%\Microsoft Visual Studio\2019\<Edition>\Common7\IDE

  • Type devenv /setup and press enter

  • When the command prompt returns, you're done. Close the command window, reopen Visual Studio, and test to see if the error's resolved.

More Information

https://msdn.microsoft.com/en-us/library/ex6a2fad.aspx

Tony_Henrich
  • 42,411
  • 75
  • 239
  • 374
  • fyi: the path for Visual Studio 2015 is: `pushd %programfiles(x86)%\Microsoft Visual Studio 14.0\Common7\IDE` – CeOnSql Jan 05 '16 at 08:22
  • I can't believe it but that's working! My issue was simular but I get the error while editing some property a WinForm object using non-ascii value. – Zyo Mar 10 '16 at 19:08
  • 1
    Correct path for VS2012 is pushd %programfiles(x86)%\Microsoft Visual Studio 11.0\Common7\IDE . What was listed is true for VS2013. – Vladimir Kocjancic Aug 03 '16 at 07:47
  • 4
    In my case the error occurred when trying to close a code window. `devenv /setup` fixed it as well. – Olivier Jacot-Descombes Oct 26 '16 at 12:06
  • This solution can also solve the trouble around Property Sheet. – javaLover Mar 24 '17 at 02:19
  • 5
    I had to run the "Developer Command Prompt for VS 2017" (which was installed with Visual Studio 2017) as Administrator, and then run `devenv /setup` from any directory – isedwards Oct 31 '17 at 17:34
  • 26
    What does `devenv / setup` do?? – Tim Jan 10 '18 at 16:00
  • @Tim, Why not click his link and find out? – NickG Jan 07 '20 at 13:14
  • 2
    @NickG: I did, but the explanation given there was rather skimpy. – Tim Jan 16 '20 at 12:44
  • 4
    Unfortunately this suggestion did not work in my case. – AH. Jul 15 '20 at 08:16
  • I try it also, not work for me too, and then I search the project files, and I write an answer for my case - seems that this message did not help at all and is for many different issues – Aristos Sep 20 '20 at 19:50
  • Same here, unfortunately I'm still in the same state. : – PHenry Feb 25 '21 at 18:30
  • 1
    deven /setup was not recognized. I typed deven and tab so it turned to deven.com and put the /setup there. The command seemed to run but unfortunately did not solve my problem in VS then. – webMac Mar 25 '21 at 09:20
  • ```cd "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE" .\devenv.exe /setup ``` – phramusca Dec 21 '22 at 14:32
37

In my case deleting .suo file in \.vs\[solutionName] folder fixed the problem in Visual Studio 2022

Elvin Mammadov
  • 25,329
  • 11
  • 40
  • 82
13

In my case, project was set to use local IIS (when the project set up to use local IIS but the app does not deployed there, it cannot load project but states clearly in the error message. However this time I was keep getting Value does not fall within the expected range with any other info.

Only "solution" worked for me was:

  • Edit csproj file
  • Set <UseIISExpress> to true
  • Set <UseIIS> to false
  • Then reload the project.

(after that you can set your local IIS again)

curiousBoy
  • 6,334
  • 5
  • 48
  • 56
9

Some projects (e.g. some web services) require that Visual Studio be run as an administrator. After a Visual Studio upgrade, I hadn't noticed that it was no longer being started with elevated privileges automatically. When I corrected this, all the projects in the solution loaded.

Graham Laight
  • 4,700
  • 3
  • 29
  • 28
  • This worked for me. I upgraded from VS 2017 to 2019 and forgot to set my shortcut to run as administrator. I have to run as admin because two of my projects use IIS. – toshiomagic Apr 07 '20 at 14:16
6

I have tried to delete the .vs hidden folder placed in the same solution directly and it works for me try this it's straightforward to fix this issue. thanks.

2

In my case, this was because I needed a specific version of the .NET Core SDK installed.

Once I got it downloaded and installed, the projects loaded fine. Unfortunately there was no additional information in the Output tab hinting at this.

emragins
  • 4,607
  • 2
  • 33
  • 48
2

In my case the file name inside the Solution .sln was wrong (not exist on disk).

I open the solution file MyFullsolution.sln using a text editor and check the Project load files and found that the project ProjectFile.csproj that fails to load was typed wrong.

How that happens ? Because I rename it from the solution some day, but I use the same ProjectFile.csproj again on a different solution! and I rename it in one solution, but the other just didn't know it... and get the same message (that actual not help at all).

So was my mistake the file rename from the other solution.

Aristos
  • 66,005
  • 16
  • 114
  • 150
1

Kind of a dumb oversight on my part.. but depending on the action that had caused it, you may want to check your console output as well. In my case it was a project that would not load. While there were no explicit errors, the consol window indicated that a file was missing based on a directive from the csproj.

ECommerce\Prod\EcommerceUtility\ECommerceCommands\ECommerceCommands.csproj : error : The imported project "C:\Program Files (x86)\MSBuildExtensionPack\4.0\MSBuild.ExtensionPack.tasks" was not found.

Confirm that the expression in the Import declaration "C:\Program Files (x86)\MSBuildExtensionPack\4.0\MSBuild.ExtensionPack.tasks" is correct, and that the file exists on disk.

Bonez024
  • 1,365
  • 1
  • 13
  • 21
0

In my case it was simple, if the file is open and then I run it, it will run. If the file is closed and then I run it by right clicking from the "Solution Explorer", then it throws the error you mentioned. So, simple steps: In the Solution Explorer,

  1. Double click on the file and open it
  2. Right click on the file and select "Start with Debugging" or "Start without Debugging"
calvin
  • 153
  • 1
  • 10
0

I also got the same error with "web" tab missing from project properties, for those having this issue can try changing the target framework of the project.When I changed target framework from 4.6.2 to 4.7.2, the web tab appeared again.

0

I have seen this box in VS-2019 16.5.4 in a Winforms/4.8 app with Std classlibs, on attempting to close one of the Winforms/4.8 source file tabs. The message came up, the tab refused to close.

Solved it by closing an re-opening the Solution.

Goodies
  • 1,951
  • 21
  • 26
0

I just had the same, it was only one file which casing this issue, When I read the solution above I was worried to fix all visual studio because one .cs file so I tried to right click on the (TAB header) beside the (X) button which closes this and click on (Close All documents)...

it worked : )

Khaleel Hmoz
  • 987
  • 2
  • 13
  • 24
0

I tried the solution described by Tony_Henrich, as it seemed helpful. However in my case, I'm building off a USB drive which is encrypted with BitLocker. I find that the *.c module I want to look at throws this error if I try to force open it with the C++ editor in VS2019 (I'm updating to 16.10.2, so whatever was just before that rev).
Visual Studio was not opening a *.c module in the editor but popping it up in Notepad. If I FORCED it to use Visual Studio C++ editor I got the "Value does not fall" message.

The file is part of a build tree in a repo I'm not responsible for, and it's not building, so at the moment I suspect Bitlocker/USB disk corruption is somehow giving Visual Studio some fits.

Tortoise-GIT Blame tool shows different/valid source code and Notepad shows a chunk missing.

My fix was to delete the file from the workspace and try seeing if GIT could restore a valid copy from the repository, and this worked. Now clicking on the *.c module in Windows Explorer and requesting to open it, no longer brings up Notepad, the file opens in Visual Studio.

Ross Youngblood
  • 502
  • 1
  • 3
  • 16
0

Setting up the dev environment for an existing project on a new server: Windows Server 2022, Visual Studio 2022, IPv6 enabled, IIS6 compatibility features installed, public IP address, domain name, web server certificate. The web application does not load. Creating the web application by hand in IIS Manager doesn't help.

Message box:

Value does not fall within the expected range

Output from: Solution:

error: The Web Application Project webapp is configured to use IIS. The Web server 'http://localhost/webapp' could not be found.

The webapp.csproj file contains:

<IISUrl>http://localhost/webapp</IISUrl>

The project loaded after changing the protocol and the name of the server to match the certificate:

<IISUrl>https://my.domain.com/webapp</IISUrl>
Tom Andraszek
  • 1,793
  • 1
  • 23
  • 30
0

In my case, the issue was caused because the project required the older version of the .NET SDK.

So, what I did was to open the "Visual Studio Installer" and, in the "Individual Components" section, chose the previous version of .NET SDK (although they were out of support in my case).

Arsen Khachaturyan
  • 7,904
  • 4
  • 42
  • 42
0

In my case I deleted .vs folder and restarted the application then it started to work!

But I have to add that I wrote code and used hot reload instead of whole application restart, so when I restarted the application it self maybe this helped if no then .vs folder deletion helped.