Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgraded to .NET 4.5, now "value does not fall within the expected range"

I am getting an error box popup that says TargetFrameworkMoniker: value does not fall within the expected range. I am using VisualStudio 2012. This is a windows form application. I have searched around and have found hat this error shows up when an element in the form has a duplicate name, which my form does not. I have upgraded all other projects in my solution and this is the last one.

steps to reproduce:

  1. Right click on the project and go to properties in the application tab

  2. Change the Target framework from .NET Framework 4, to .NET Framework 4.5

  3. Click Yes on the box that asks me if I am really sure.

  4. Error Message pops up.

I am not sure how to find the real error with stacktrace.

Does anyone have any suggestions?

like image 462
Steven Klein Avatar asked Dec 26 '13 15:12

Steven Klein


2 Answers

This still happens in VS 2017 and VS 2019, for instance when you go from Framework 4.5 to 4.5.2 or something similar. It can happen to any type of project, and usually when there are one or more referenced projects that you are updating one by one to a new .NET version.

The cause is as follows: the system updates the version of the framework in the corresponding file and saves it to disk, but somehow the dirty-flag is still set after it tries to close/reopen the project as it is usually doing.

Visual Studio then tries to update the in-memory file, which is already refreshed with the new version, but it expects the old version to be there. Hence the error: in your case, it expected to see 4.0, but it was already 4.5.

The bug in VS has never been fixed, and is a synchronization issue between the loaded an in-memory files and what's already on disk.

Closing / reopening Visual Studio will solve this. Unloading / reloading (right-mouse click on project) the individual project will also solve the issue.

This seems to happen when you update a referenced project first, and then the using project. But I couldn't consistently repro it in all scenarios.

It has nothing to do with the 'duplicate name' situation explained in some blog posts that you referred to.

like image 152
Abel Avatar answered Nov 19 '22 15:11

Abel


I had the same issue in Visual Studio 2019 today. Closing and reopening Visual Studio fixed the issue.

like image 22
Ajith Avatar answered Nov 19 '22 15:11

Ajith