3

I get "Object reference not set to instance of an object" when I try to open my edmx file in EF 6. Is there any way to figure out what its missing?

2 Answers2

0

Closing and opening the visual studio worked for me.

Amit K
  • 9
  • 2
0

Same as Cannot import anymore tables into edmx. "Running transformation: System.NullReferenceException: Object reference not set to an instance of an object."

Go to

C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes

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);

Basically, you need to add the BindingFlags.Public to the options inside the GenerationEnvironment.

This is a documented bug from VS2022. It looks like it will be fixed in new releases. (https://developercommunity.visualstudio.com/t/Cannot-import-anymore-tables-into-edmx/10368835)

maurow
  • 1
  • 1