"Value does not fall within the expected range" when trying to add a reference in a project
Visual StudioVisual Studio-2013Visual Studio-2019Visual Studio Problem Overview
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?
Visual Studio Solutions
Solution 1 - Visual Studio
I did a 'devenv /setup' and that fixed it.
Detail
-
Exit Visual Studio
-
Click
Start
-
Type
cmd
, right clickCommand Prompt
and selectRun 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
Solution 2 - Visual Studio
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>
totrue
- Set
<UseIIS>
tofalse
- Then reload the project.
(after that you can set your local IIS again)
Solution 3 - Visual Studio
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.
Solution 4 - Visual Studio
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.
Solution 5 - Visual Studio
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.
Solution 6 - Visual Studio
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,
- Double click on the file and open it
- Right click on the file and select "Start with Debugging" or "Start without Debugging"
Solution 7 - Visual Studio
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.
Solution 8 - Visual Studio
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.
Solution 9 - Visual Studio
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 : )
Solution 10 - Visual Studio
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.
Solution 11 - Visual Studio
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.
Solution 12 - Visual Studio
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>