When trying to regenerate/generate entity types EF6.Utilities.CS.ttinclude throws nullreference at line 1928
See original GitHub issueInclude your code
The problem happens with my capstone project (college course) so I will need to include the code privately (I can dm it to a maintainer on discord, I am Magic Mage#9260). Basically, expand the project that contains the edmx, expand models, expand the edmx, and then right click the non-context *.tt file and select “Debug T4 Template.”. After that notice that the exception is thrown in the file that I noted in the issue name at the exact line. Opening the edmx file and saving it without changes also reproduces the problem with an unhelpful stack trace that the “Debug T4 Template.” helps resolve.
Include stack traces
This is the exception I get when the text template tries to generate the entity types:
Stack Trace:
Running transformation: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.VisualStudio.TextTemplatingA5ABE4DEDDB259CC1BBB7344A66833B5C405B93776F35DD6B3989F1A41088892007BA7448761011D5E3DBAEB5B93439FADE79CC07BC15250A1781EBE8A44F37E.GeneratedTextTransformation.DynamicTextTransformation.get_GenerationEnvironment()
at Microsoft.VisualStudio.TextTemplatingA5ABE4DEDDB259CC1BBB7344A66833B5C405B93776F35DD6B3989F1A41088892007BA7448761011D5E3DBAEB5B93439FADE79CC07BC15250A1781EBE8A44F37E.GeneratedTextTransformation.EntityFrameworkTemplateFileManager..ctor(Object textTransformation)
at Microsoft.VisualStudio.TextTemplatingA5ABE4DEDDB259CC1BBB7344A66833B5C405B93776F35DD6B3989F1A41088892007BA7448761011D5E3DBAEB5B93439FADE79CC07BC15250A1781EBE8A44F37E.GeneratedTextTransformation.EntityFrameworkTemplateFileManager.VsEntityFrameworkTemplateFileManager..ctor(Object textTemplating)
at Microsoft.VisualStudio.TextTemplatingA5ABE4DEDDB259CC1BBB7344A66833B5C405B93776F35DD6B3989F1A41088892007BA7448761011D5E3DBAEB5B93439FADE79CC07BC15250A1781EBE8A44F37E.GeneratedTextTransformation.EntityFrameworkTemplateFileManager.Create(Object textTransformation)
at Microsoft.VisualStudio.TextTemplatingA5ABE4DEDDB259CC1BBB7344A66833B5C405B93776F35DD6B3989F1A41088892007BA7448761011D5E3DBAEB5B93439FADE79CC07BC15250A1781EBE8A44F37E.GeneratedTextTransformation.TransformText()
Possible Workarounds
Because EFCore 7 has templating support, I am considering creating a dummy project that uses .NET 6 and references EFCore 7 (and uses dotnet ef) just for generating the scaffolded code and then manually add the code files into the .NET Framework project (as it should still compile under .NET Framework with similar code. Ironically none of the edmx issues I been having recently happen when using EFCore so my owner classmates working on the same project with me are also considering it just so we can fix the edmx issues we are facing for good due to time restraints.
Include verbose output
Currently because this happens with the text templates, I do not think it’s possible to do verbose output. However, I did not try deleting all of the packages and then force restore them again in case of corrupted package data yet though.
Include provider and version information
EF version: 6.4.4 Database provider: SQL Server Target framework: net472 Operating system: Windows 11 IDE: Visual Studio 2022 latest preview (17.6 preview 2)
Issue Analytics
- State:
- Created 6 months ago
- Comments:13 (7 by maintainers)
I actually prefer the source generator more though and find that it is far better and performant than the template with better features. Also I sorta shared it with my capstone project to companies that were there and they sorta liked the project and found it to be a great thing even for them to use over Microsoft’s text templates that can break at any time. Also works inbox without need to remember to delete extra semicolons. Also it is technically not wasting my time as broken text templates wasted it far more when I was in my capstone class.
Nope. Using VS 2022 Pro on latest update. I’m going to file a bug report with the VS team to see if they can get this fixed in a timely manner. Probably one of the updates broke it since it worked just fine for a long time.