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.
The Microsoft.VisualStudio.TextTemplating.GeneratedTextTransformation.GenerationEnvironment property access appears to have changed from non public to public in the latest update (ie. 17.6.2)
You can modify the EF.Utility.CS.ttinclude and EF6.Utility.CS.ttinclude files in C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes to fix this by changing
_generationEnvironment = type.GetProperty("GenerationEnvironment", BindingFlags.Instance | BindingFlags.NonPublic);
to
_generationEnvironment = type.GetProperty("GenerationEnvironment", BindingFlags.Instance | BindingFlags.Public);
EDIT: Looks like it will be fixed in the next VS version https://github.com/dotnet/ef6tools/commit/89cd126fa8ebfd40c3b5e781232be940711cf726
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With