sjh37 / EntityFramework-Reverse-POCO-Code-First-Generator

EntityFramework Reverse POCO Code First Generator - Beautifully generated code that is fully customisable. This generator creates code as if you reverse engineered a database and lovingly created the code by hand. It is free to academics (you need a .edu or a .ac email address), not free for commercial use. Obtain your licence from
https://www.reversepoco.co.uk/
Other
700 stars 230 forks source link

Error - Running transformation: System.NullReferenceException: Object reference not set to an instance of an object. #810

Closed szienciklf closed 11 months ago

szienciklf commented 11 months ago

Cannot update my db from the tt file. Getting the following error. I have been successfully using the same project for 6+ months. Have not changed anything. Just added a new table to the project and got the following when I updated the tt file. I have tried unistalling and reinstalling the extension. I also have tried restarting VS and the machine, running in admin mode. I am running windows 11, the machine.config has system.data.sqlclient installed. The VS project is using the .NET 4.8 Framework.

I am under a tight project deadline.
Please advise.


Here are the basic TT settings. I removed the connection string.


// For help on the various Types below, please read https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/wiki/Common-Settings.*Types-explained // The following entries are the only required settings. Settings.DatabaseType = DatabaseType.SqlServer; // SqlServer, SqlCe, PostgreSQL. Coming next: MySql, Oracle Settings.TemplateType = TemplateType.Ef6; // EfCore7, EfCore6, EfCore5, EfCore3, EfCore2, Ef6, FileBasedCore2-7. FileBased specify folder using Settings.TemplateFolder Settings.GeneratorType = GeneratorType.Ef6; // EfCore, Ef6, Custom. Custom edit GeneratorCustom class to provide your own implementation

Settings.FileManagerType         = FileManagerType.VisualStudio; // .NET Core project = EfCore; .NET 4.x project = VisualStudio; No output (testing only) = Null
Settings.ConnectionString        = "xxxxxxxxxxxxxxxxxxxx"; // This is used by the generator to reverse engineer your database
Settings.ConnectionStringName    = "DCXToolsContext"; // ConnectionString key as specified in your app.config/web.config/appsettings.json. Not used by the generator, but is placed into the generated DbContext constructor.
Settings.DbContextName           = "DCXToolsContext"; // Class name for the DbContext to be generated.
//Settings.DbContextInterfaceName= "IDCXToolsContext"; // Defaults to "I" + DbContextName or set string empty to not implement any interface.
Settings.GenerateSeparateFiles   = true;
Settings.Namespace               = DefaultNamespace; // Override the default namespace here. Please use double quotes, example: "Accounts.Billing"
Settings.TemplateFolder          = Path.Combine(Settings.Root, "Templates"); // Only used if Settings.TemplateType = TemplateType.FileBased. Specify folder name where the mustache folders can be found. Please read https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/wiki/Custom-file-based-templates
Settings.AddUnitTestingDbContext = false; // Will add a FakeDbContext and FakeDbSet for easy unit testing. Read https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/wiki/FakeDbContext

I get the following error in VS error list:


Error Running transformation: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.VisualStudio.TextTemplatingB1F8828390E131E68B779BF45AC6EE5BFC51F180D0206C9C4D4115C7236554626A0929F5E659DB6347FBD5399FA5C44FA9DE81361ABD9658E8985DBE54FAD922.GeneratedTextTransformation.VisualStudioFileManager.Process(Boolean split) in C:\Downloads\Code\Littelfuse.DCXUtils\Littelfuse.DCXUtils\Littelfuse.BlockDiagrams.Business\DAL\Models\EF.Reverse.POCO.v3.ttinclude:line 1897 at Microsoft.VisualStudio.TextTemplatingB1F8828390E131E68B779BF45AC6EE5BFC51F180D0206C9C4D4115C7236554626A0929F5E659DB6347FBD5399FA5C44FA9DE81361ABD9658E8985DBE54FAD922.GeneratedTextTransformation.FileManagementService.Process(Boolean split) in C:\Downloads\Code\Littelfuse.DCXUtils\Littelfuse.DCXUtils\Littelfuse.BlockDiagrams.Business\DAL\Models\EF.Reverse.POCO.v3.ttinclude:line 1798 at Microsoft.VisualStudio.TextTemplatingB1F8828390E131E68B779BF45AC6EE5BFC51F180D0206C9C4D4115C7236554626A0929F5E659DB6347FBD5399FA5C44FA9DE81361ABD9658E8985DBE54FAD922.GeneratedTextTransformation.TransformText() in C:\Downloads\Code\Littelfuse.DCXUtils\Littelfuse.DCXUtils\Littelfuse.BlockDiagrams.Business\DAL\Models\DCXToolsDb.tt:line 717 Littelfuse.BlockDiagrams.Business C:\Downloads\Code\Littelfuse.DCXUtils\Littelfuse.DCXUtils\Littelfuse.BlockDiagrams.Business\DAL\Models\EF.Reverse.POCO.v3.ttinclude 1897



I also get the following added to my XXX.Db.cs file


// ------------------------------------------------------------------------------------------------ // WARNING: Failed to load provider "System.Data.SqlClient" - Object reference not set to an instance of an object. // Allowed providers: // "System.Data.Odbc" // "System.Data.OleDb" // "System.Data.OracleClient" // "System.Data.SqlClient" // "Microsoft.SqlServerCe.Client.4.0" // "Microsoft.Data.SqlClient"

/ at Microsoft.VisualStudio.TextTemplatingB1F8828390E131E68B779BF45AC6EE5BFC51F180D0206C9C4D4115C7236554626A0929F5E659DB6347FBD5399FA5C44FA9DE81361ABD9658E8985DBE54FAD922.GeneratedTextTransformation.DynamicTextTransformation.get_GenerationEnvironment() in C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF6.Utility.CS.ttinclude:line 1928 at Microsoft.VisualStudio.TextTemplatingB1F8828390E131E68B779BF45AC6EE5BFC51F180D0206C9C4D4115C7236554626A0929F5E659DB6347FBD5399FA5C44FA9DE81361ABD9658E8985DBE54FAD922.GeneratedTextTransformation.EntityFrameworkTemplateFileManager..ctor(Object textTransformation) in C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF6.Utility.CS.ttinclude:line 1665 at Microsoft.VisualStudio.TextTemplatingB1F8828390E131E68B779BF45AC6EE5BFC51F180D0206C9C4D4115C7236554626A0929F5E659DB6347FBD5399FA5C44FA9DE81361ABD9658E8985DBE54FAD922.GeneratedTextTransformation.EntityFrameworkTemplateFileManager.VsEntityFrameworkTemplateFileManager..ctor(Object textTemplating) in C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF6.Utility.CS.ttinclude:line 1784 at Microsoft.VisualStudio.TextTemplatingB1F8828390E131E68B779BF45AC6EE5BFC51F180D0206C9C4D4115C7236554626A0929F5E659DB6347FBD5399FA5C44FA9DE81361ABD9658E8985DBE54FAD922.GeneratedTextTransformation.EntityFrameworkTemplateFileManager.Create(Object textTransformation) in C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF6.Utility.CS.ttinclude:line 1629 at Microsoft.VisualStudio.TextTemplatingB1F8828390E131E68B779BF45AC6EE5BFC51F180D0206C9C4D4115C7236554626A0929F5E659DB6347FBD5399FA5C44FA9DE81361ABD9658E8985DBE54FAD922.GeneratedTextTransformation.VisualStudioFileManager.Init(GeneratedTextTransformation textTransformation) in C:\Downloads\Code\Littelfuse.DCXUtils\Littelfuse.DCXUtils\Littelfuse.BlockDiagrams.Business\DAL\Models\EF.Reverse.POCO.v3.ttinclude:line 1877 at Microsoft.VisualStudio.TextTemplatingB1F8828390E131E68B779BF45AC6EE5BFC51F180D0206C9C4D4115C7236554626A0929F5E659DB6347FBD5399FA5C44FA9DE81361ABD9658E8985DBE54FAD922.GeneratedTextTransformation.FileManagementService.Init(Dictionary`2 filters, Type fileManagerType) in C:\Downloads\Code\Littelfuse.DCXUtils\Littelfuse.DCXUtils\Littelfuse.BlockDiagrams.Business\DAL\Models\EF.Reverse.POCO.v3.ttinclude:line 1727 at Microsoft.VisualStudio.TextTemplatingB1F8828390E131E68B779BF45AC6EE5BFC51F180D0206C9C4D4115C7236554626A0929F5E659DB6347FBD5399FA5C44FA9DE81361ABD9658E8985DBE54FAD922.GeneratedTextTransformation.Generator.Init(DatabaseReader databaseReader, String singleDbContextSubNamespace) in C:\Downloads\Code\Littelfuse.DCXUtils\Littelfuse.DCXUtils\Littelfuse.BlockDiagrams.Business\DAL\Models\EF.Reverse.POCO.v3.ttinclude:line 4172 at Microsoft.VisualStudio.TextTemplatingB1F8828390E131E68B779BF45AC6EE5BFC51F180D0206C9C4D4115C7236554626A0929F5E659DB6347FBD5399FA5C44FA9DE81361ABD9658E8985DBE54FAD922.GeneratedTextTransformation.GeneratorFactory.Create(FileManagementService fileManagementService, Type fileManagerType, String singleDbContextSubNamespace) in C:\Downloads\Code\Littelfuse.DCXUtils\Littelfuse.DCXUtils\Littelfuse.BlockDiagrams.Business\DAL\Models\EF.Reverse.POCO.v3.ttinclude:line 6351/ // ------------------------------------------------------------------------------------------------

sjh37 commented 11 months ago

A lot of people ran into this. This was fixed in visual studio 17.6.4. You need to update visual studio. See Reverse POCO issue #804 and here is the Microsoft notification https://developercommunity.visualstudio.com/t/TextTransformationGenerationEnvironment/10369514