30

How can I resolve these errors:

  1. Loading the include file 'EF.Utility.CS.ttinclude' returned a null or empty string.
  2. Value does not fall within the expected range.

Tools Used: VS 2012, Entity Framework 5.0.0, T4MVCExtensions 3.5.0, .NET Framework 4.5

I've been using EF and T4 templates in a project within a large MVC solution without incident. Now, when I right-click on the edmx diagram, EF responds with the message: Value does not fall within the expected range. When I compile the EF project it responds with these messages:

  1. Loading the include file 'EF.Utility.CS.ttinclude' returned a null or empty string. The transformation will not be run. C:\Projects\NSAForms\NSAForms\NSAFormsEDM\NSAFormsEntities.tt
  2. Failed to resolve include text for file:C:\Projects\NSAForms\NSAForms\NSAFormsEDM\EF.Utility.CS.ttinclude C:\Projects\NSAForms\NSAForms\NSAFormsEDM\NSAFormsEntities.tt

Every table in the database has a primary key. I'm struck by how suddenly this issue appeared. Does anyone have some suggestions how to resolve this issue?

Thanks in advance,

Arnold

Arnold
  • 515
  • 1
  • 9
  • 18
  • This sounds less like a db issue and more like a code/solution issue - Do you work in a team and synchronise through source control? Is it possible someone has failed to check a new file in? Does anyone else experience these issues? Does reverting to earlier versions of your code resolve the issue? If so, is it possible to identify the problem changeset and do a diff? – Basic Feb 21 '13 at 10:19
  • @Basic. I reverted back to a deployed version dated 2/15/2013. All the files are there. Still getting the 'EF.Utility.CS.ttinclude' error on a compile. Still can't right-click on the edmx designer without getting: Value does not fall within the expected range. Thanks – Arnold Feb 21 '13 at 11:18
  • I created a totally new project and added EF. Getting the very same errors. – Arnold Feb 21 '13 at 11:23
  • Interesting - Have you already seen [this answer](http://stackoverflow.com/a/8210150/156755)? It implies that you might need the VS2012 SDK. I admit I don't know what the problem is and am guessing but if I were you, I'd first do a repair install of VS2012 then try installing the SDK. Is it possible you've got any extensions which are interfering? – Basic Feb 21 '13 at 11:41
  • When I right-click in the new project I sometimes see a different error: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) – Arnold Feb 21 '13 at 11:42
  • I repaired the VS2012 install and then reinstalled the SDK. I've tried pointing to other databases, but still the same errors. – Arnold Feb 21 '13 at 16:09
  • How can I find out what is making 'EF.Utility.CS.ttinclude' throw the error when compiling? Thanks. – Arnold Feb 21 '13 at 18:42
  • You could configure your build to add the `/verbosity:diag` option which should give you mountains of info. ([MsBuild command line reference](http://msdn.microsoft.com/en-gb/library/vstudio/ms164311.aspx)). You could also use [Fusion](http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.71).aspx) which monitors and reports on all attempts by the framework to load asemblies (You'd normally use this on your compiled exe but you might be able to get away with running it against msbuild/devenv to see what they're trying to do but I must admit I've never tried it) – Basic Feb 21 '13 at 18:52
  • Oh and if you'd care to share a minimal test solution, I'd be happy to load it up in my VS and see if I can replicate the issue – Basic Feb 21 '13 at 18:55

8 Answers8

70

I had very similar issue and I tried with VS2012 and VS2013.

After reinstalling Entity Framework 6 Tools for Visual Studio 2012 http://www.microsoft.com/en-us/download/confirmation.aspx?id=40762 every thing went back to normal.

odesuk
  • 1,197
  • 1
  • 12
  • 10
  • 1
    how do u add it to source control ?? you will install in every machine ? – Peru Apr 01 '14 at 10:20
  • Thanks, This saved lot of trouble for me. – Bhalchandra K Aug 11 '14 at 09:41
  • I had installed EF6 update 6.1.1 and was wondering why I had this error until I found your comment. Tools must be upgraded to be same version as EF6 libraries. The error I had was: Error 168 "The provider did not return a ProviderManifest instance. Could not determine store version; a valid store connection or a version hint is required." Thanks for your help. – codea Sep 14 '14 at 13:56
  • I wish I could +9999999 this. What a headache! Thanks a ton! – Timothy Dec 08 '14 at 19:49
  • 1
    I had this error in VS2012 with EF6 (a colleague had started the project in VS2013). The error text was `failed to resolve include text EF_6_.Utility.CS.ttinclude`. Installing these EF 6 Tools for VS2012 solved the problem. – bvgheluwe May 07 '15 at 20:05
  • 1
    Didn't fix it for me. My nightmare goes on. – SteveCav Jun 23 '15 at 05:38
  • Microsoft ... just say no. – Keith John Hutchison Oct 22 '15 at 07:57
  • still issue for me – Reza Oct 05 '17 at 15:42
28

In VS 2012, the EF.Utility.CS.ttinclude file will only be installed if the Microsoft Web Developer Tools or Microsoft SQL Server Data Tools component is selected.

bricelam
  • 28,825
  • 9
  • 92
  • 117
  • 3
    +1 Good info but could you consider including a link for further reading? – Basic Feb 22 '13 at 00:42
  • 1
    @Basic Unfortunately, the only links I have are [a comment on our blog](http://blogs.msdn.com/b/adonet/archive/2012/08/15/ef5-released.aspx#10369935), and [a discussion on CodePlex](http://entityframework.codeplex.com/discussions/401836). I'll bring it up to the team again to see if we can get it somewhere a little more obvious like the [Get It](http://msdn.microsoft.com/en-us/data/ee712906) page. – bricelam Feb 22 '13 at 00:55
  • 1
    @Basic. Thanks for asking Brice for more information and explanation. I've spent too much precious work time chasing down scraps of documentation. By the time I'd gotten back to Stack to see Brice's answer, I'd already started implementing Telerik's ORM with zero problems. I haven't tested yet, but what a nice change it was to work with a tool that didn't depend upon other unknown (to me) library. – Arnold Feb 25 '13 at 21:11
  • Selected at installation time? Selected when and where? – froggythefrog Nov 10 '13 at 03:57
  • 1
    @froggythefrog Yes, during install. If you've already installed, select the program in Programs and Features (or Add/Remove Programs), click Change, then click Modify. – bricelam Nov 11 '13 at 16:43
  • @bricelam how ab installing in NUGET ? how do i add to source controller ? – Peru Apr 01 '14 at 10:23
  • I installed both but still issue – Reza Oct 05 '17 at 15:42
  • Regarding the original post: the solution is to install the Entity Framework 6 Tools as part of the Visual Studio install (Individual Components section). – Patrick Peters Sep 05 '19 at 06:33
5

Reinstalling Entity Framework 6 Tools for Visual Studio 2012 http://www.microsoft.com/en-us/download/confirmation.aspx?id=40762 work for me

Alexandre
  • 51
  • 1
  • 2
2

For VS2017, I ended up adding EF6.Utility.CS.ttinclude to model's folder. This resolved my issue with MySql and EF.

File can be found: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF6.Utility.CS.ttinclude

UPDATE To avoid doing the above, removing the entities completely then adding back in fixed the issue.

Spencer
  • 319
  • 5
  • 10
1

Had this issue with a recent install of VS2017 Enterprise after already having this functionality working in Professional.
The solution for me was to:

  1. Open the Visual Studio Installer program and "Modify" my Enterprise installation.
  2. Select "ASP.NET and web development" under the Web & Cloud section
  3. Click "Modify" in bottom right enter image description here

It's probably worth noting that I already had EF6 installed and did not need to re-install it to get this to work.

After completing those steps and firing up Visual Studio, the error went away and I was able to generate my classes successfully. Hope this helps!

EJay
  • 1,079
  • 2
  • 12
  • 23
0

Visual Studio 2017

was getting the same error but only in a test project. after reviewing the test project and the other project successfully referencing that file i found that adding the following to the app.config of the failing project resolved my issue

  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
  <connectionStrings>
workabyte
  • 3,496
  • 2
  • 27
  • 35
0

All of the above solutions did not work for me so I created a new project to see if the problem persists but the error did not occur in the newly created project. I then compared the project with the old backup to check recent changes made and found the problem. I recently had upgraded a package Clarius.TransformOnBuild to more recent version after downgrading the package the error went away.

irfandar
  • 1,690
  • 1
  • 23
  • 24
0

In my case the issue was caused by a bizarre folder name (with %20 instead of spaces). I just made a directory junction to the same folder with spaces instead of %20 and it solved the issue.

Here is the PowerShell command I used to make the junction:

cd "c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\Microsoft\"
mklink /j "Entity Framework Tools" "Entity%20Framework%20Tools"
Junction created for Entity Framework Tools <<===>> Entity%20Framework%20Tools

You can then use ls look at the directory contents, and you should see these two lines (edited for brevity):

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
...
d----l        2/27/2019   9:57 AM                Entity Framework Tools
d-----        2/26/2019  12:24 PM                Entity%20Framework%20Tools
...

Under Mode, the l indicates that it is a "link" (aka junction), and the d indicates it's a directory. By making a junction instead of renaming the folder, you can be sure that both directory names will always work.

QuickDanger
  • 1,032
  • 11
  • 18