Symptom

File has already been deleted (from source control and from the filesystem). Yet – the file shows up in the Visual Studio solution (with a yellow warning icon next to it). When one tries to compile, one sees the above error:

source file could not be opened ‘unspecified error ‘

What does not work

By now you’ve already tried all the usual suspects. Tried refreshing, closing (and re-opening VS), clean command etc. Nothing seems to work. 

The Source of the Problem

Something in Visual Studio is obviously remembering a reference to the file path and name. An obvious suspect is the .csproj file for your project. If you look inside it, you will see a reference to the source file that is throwing the above error.

The Solution

Simply delete the entry from your .csproj file – and you should be good to go. Somehow, the .csproj did not remove the entry when you removed this file (perhaps because you first deleted it from the filesystem before deleting it from the solution). That’s it – if you run into this obscure ‘Source file could not be opened  – Unspecified Error’, try editing your .csproj file and see if that fixes it.

Anuj holds professional certifications in Google Cloud, AWS as well as certifications in Docker and App Performance Tools such as New Relic. He specializes in Cloud Security, Data Encryption and Container Technologies.

Initial Consultation

Anuj Varma – who has written posts on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.