David Sherwood
David Sherwood

Reputation: 41

Opening a edmx file gets error "Object reference not set to instance of an object"

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?

Upvotes: 3

Views: 817

Answers (2)

maurow
maurow

Reputation: 1

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)

Upvotes: 0

Amit K
Amit K

Reputation: 9

Closing and opening the visual studio worked for me.

Upvotes: 0

Related Questions