Getting CSC errors on missing Entity Framework context files


I'm getting an issue that appears to be intermittent but I have no idea why it happens. 

Today I did a "get latest" on a project I am contributing to and it downloaded all the files as expected. However, when I did a clean and build I had lots of errors of type CS2001 saying class files were missing. I knew they are Entity Framework related files as the referenced project is our Entity Framework class library and the missing files all start with "tbl_" which is our convention for Entity Framework generated class objects from our SQL Servers database tables. There are also some store procedure object classes showing as missing too saying it cannot find them also. 

I'm very confused as I'm sure Entity Framework context files are auto generated but I can see the context files! 

I have had this before and it took ages to fix. Sadly, I cannot remember how I did it. 

Can anyone help?

User_59985 Profile Image


Rating: 40


Answers (1)

Yes, I get this all the time. Seems to be an issue from Entity Framework 6 onwards. Very annoying bug which occurs when you download the files from source control.

You are correcting that the files are generated. What's likely happened is some of the files that have dependency's have not generated. You can see them in your project as they will have the same yellow explanation mark icon as a missing file in your solution explorer.

To fix this, do the following.

  1. Expand your class library that contains your EF context.
  2. Expand your .EDMX file.
  3. This will reveal 4 child objects.
  4. Expand the last child object with .tt as the prefix
  5. See if you can see any files that are indicated as missing – See example image below.
  6. Right click on the .tt parent file and select “Run Custom Tool”
  7. Once complete click Refresh at the top of Solution Explorer
  8. Your files will now be shown as available.

Now when you build it should work fine.

Above shows how it should look if you experience this issue. this is from a project i contribute with the exact same issue.

This is where "Run Custom Tool" is located.

Hope this helps


JGilmartin Profile Image


Technical Architect at Pinewood Technologies

Rating: 3180

C# Expert

Online Now

great thanks, this fixed it for me
16/4/2017 19:33

Question Statistics
  • Views: 2100
  • Answers: 1
  • Comments: 0
  • Asked: User_59985 (40)
  • Date: 16/4/2017 19:20
C# .NET Visual Sudio

© 2016 - 2020 - IntermittentBug