[Solved] Error CS2001: Source file ‘.cs’ could not be found [closed]

I am getting the following error on a project of mine when I try to build… Error CS2001: Source file ‘.cs’ could not be found. I took the two files that are causing this error out on purpose because they conflict with other files and cannot be in there. How can I resolve this error without putting the 2 files back in the solution?

Solution #1:

They are likely still referenced by the project file. Make sure they are deleted using the Solution Explorer in Visual Studio – it should show them as being missing (with an exclamation mark).

Respondent: Tim Rogers
Solution #2:

I open the project,.csproj, using a notepad and delete that missing file reference.

Respondent: AdnR
Solution #3:

I had this problem, too.

Possible causes in my case: I had deleted a duplicated view twice and a view model.
I reverted one of the deletes and then the InitializeComponent error appeared.

I took these steps.

  1. I checked all of the solutions mentioned on this question. The class
    name and build action were correct.
  2. I Cleaned my Solution and rebuilt. Another error appeared. “Error CS2001: Source file ‘.cs’ could not be found”
  3. I found this answer and followed the steps.
  4. I reloaded the project and cleaned/rebuilt again.
  5. My solution builds without errors and my application works now.
Respondent: Eric
Solution #4:

In my case, I add file as Link from another project and then rename file in source project that cause problem in destination project. I delete linked file in destination and add again with new name.

Respondent: Amir Aghajani
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.