question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When trying to regenerate/generate entity types EF6.Utilities.CS.ttinclude throws nullreference at line 1928

See original GitHub issue

Include 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: image

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:closed
  • Created 6 months ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
AraHaancommented, Aug 12, 2023

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.

1reaction
AYColumbiacommented, May 23, 2023

Have you tried the latest VS preview?

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity Framework 6 t4 code generation not working in ...
Utility.CS.ttinclude . So I tried the one we had before, still same error in VS2022. I tried to apply the latest entity 6.4....
Read more >
Create or recreate a Model does not works any more for ...
Trying to create a project with the ADO.NET Entity Data Model Template, it performs all the steps, at the end when saving it...
Read more >
System.NullReferenceException message in creating ...
I tried to add new ADO .Net Entity Data Model into the Model folder and always received the System.NullReferenceException error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found