Closed abelbraaksma closed 7 years ago
Tagging this for VS Updates. We should be able to address this when we move onto the new Roslyn project system.
I have tried to repro this in VS2017, but it doesn't happen anymore, thanks for the much improved folder support! 🥇
If your
fsproj
file contains two or more references to a file in a folder and between those files there's an item from another folder or from the root, the project file cannot be opened.In other words, using regular commands or menu actions, the
fsproj
file can get corrupted like as follows, which compiles fine but cannot be opened in Visual Studio:somefolder\source1.fs
source2.fs
somefolder\source3.fs
Detailed (and, even though there's a lot of text, quite straightforward) repros follow:
Repro steps
"Manual" repro method:
*.fs
files to the project next to the defaultProgram.fs
*.fs
files to the folder (either manually, or again using the FS Powertools "Move to folder" command)*.fsproj
file for editing and put the remaining file in the root (from step (1)) between the two files in the folder. Yourfsproj
file looks something like this:Reopening the project is now impossible and you'll receive an error.
"Accidental" repro method
This is one of many ways to accidentally get to the same as above, this works without any addins installed (i.e., in SafeMode).
You will now get a popup "Object reference not set to an object", i.e., a
NullReferenceException
.You will also see that the
Ctrl-X
had no effect, it acted as aCtrl-C
(copy) and paste. The filename will haveCopy of
prepended, even though that is not necessary as it appears in a new folder.fsproj
file you will find thecopy of
file on top of all file referencesRemarks/alternates/related bugs
NullReferenceException
and places the new reference on top in thefsproj
file (leading to load errors next time)fsproj
file. No load errors (but possible compile errors)fsproj
file)Notes:
Expected behavior
NullReferenceException
should not happen, for sure. The other error is surprising, especially if it is possible to have a loaded project that compiles, and that, upon reopening, is invalid.fsproj
file is improperly edited), except that it can be made clearer.Actual behavior
(the following items correspond numerically with the ones under Expected behavior)
If you Ctrl-X/Ctrl-V you see this (reminiscent of a
NullReferenceException
):You see errors when reloading:
You get the following error in a popup when you reopen or reload such project:
In the solution explorer you'll see the following:
An invalid project file compiles fine
Ctrl-X does not cut, it leaves the original file in place and copies instead
The location shown in Solution Explorer does not match the location in the
fsproj
filefsproj
file is invalidKnown workarounds
fsproj
file manually by reordering the items or removing the offending ones.Ctrl-X/Ctrl-V
orCtrl-C/Ctrl-V
or the corresponding menu itemsfsproj
file and rearrange the items, and at the same time rearrange them on disk)fsproj
files.Related information
I have written two repro ways above, though it is possible this has been reported and/or is reproducible with different repro steps.
I realize this error is caused by Visual Studio not being able to render a directory multiple times (it would lead to two identical directory entries in the solution explorer). I don't know if this can be resolved by the F# team. However, the root cause of this error can definitely be mitigated, i.e. by making sure that Ctrl-X / Ctrl-V either works correctly, or doesn't work at all (drop the feature).
Worries
While there is something to say for the error to popup (apart from the NRE), being able to continue working when the error does not popup means you can edit in an incorrect environment for a long time, which may lead to hard-to-resolve issues later (apart from the surprise when you find you cannot reopen your project).
Suggestions
If we have influence on the error, I would like to discuss a better text. If not, we should strive to prevent it from happening in the first place.
Reproducible: