entity-frameworkt4.net-4.8edmxedmx-designer

Net Framework 4.8 EF6 EDMX T4 Error _generationEnvironment is NULL


This started with an EDMX suddenly not generating class files. The .context.cs file contains the class declaration like

  public virtual DbSet<myTable> myTable { get; set; }

but the actual class files are not being generated. Both .tt files are there & "Run Custom Tool" did not help.

On debugging the Model.tt T4 template this declaration:

public StringBuilder GenerationEnvironment { get { return (StringBuilder)_generationEnvironment.GetValue(_instance, null); } }

produces

"System.NullReferenceException: 'Object reference not set to an instance of an object.'"

the _generationEnvironment variable is NULL.

To be sure that database changes were not triggering this I recreated the Model including only a table that had not been modified, but with no improvement.

Unfortunately I don't have the luxury of moving this to Code-First and Core so any suggestions would be gratefully received.


Solution

  • Same problem here. Using Visual Studio Community 2022 version 17.6.2

    C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF6.Utility.CS.ttinclude:line 1928

    Edit: Problem has gone after roll back to 17.5.3