entity-framework-6visual-studio-2022edmx

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


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


Solution

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