VS2022, ver. 17.6.2 – EntityFramework6 broken

VS2022, ver. 17.6.2 – EntityFramework6 broken

VS2022, ver. 17.6.2 – EntityFramework6 broken

Abstract: In Visual Studio 2022, ver. 17.6.2, Entity Framework 6 (Classic) is broken, adding new DB tables in the “Database-First” approach does not work. We are showing how to manually fix it.

Symptoms:

  • In Visual Studio 2022, ver. 17.6.2, Entity Framework 6 (Classic) is broken, adding new DB tables in the “Database-First” approach does not work.
  • You get build error: “Running transformation: System.NullReferenceException: Object reference not set to an instance of an object.”

Reason:

Seems like a bug in Visual Studio 2022, ver. 17.6.2

Manual Fix:

I tried steps from [1] by Chirag Prajapati and they worked:

====================================
Start Notepad in administrator mode, and open the file (substituting Community for Professional or Enterprise depending on your version):
C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF6.Utility.CS.ttinclude

Update the following code in DynamicTextTransformation (approx line 1920) and change:

_generationEnvironment = type.GetProperty(“GenerationEnvironment”, BindingFlags.Instance | BindingFlags.NonPublic);

to

_generationEnvironment = type.GetProperty(“GenerationEnvironment”, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
=================================================

Conclusion

Will please somebody post when that bug is fixed?

References:

[1] https://developercommunity.visualstudio.com/t/Cannot-import-anymore-tables-into-edmx/10368835?pageSize=15&sort=active&openOnly=false&closedOnly=false&topics=C++&q=System.NullReferenceException%3A+Object+reference+not+set+to+an+instance+of+an+object.&page=3

No Comments

Sorry, the comment form is closed at this time.