-
-
Notifications
You must be signed in to change notification settings - Fork 334
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Bug description / exact reproduction steps
When using T4 Split templates (UseT4: true, UseT4Split: true) with .NET 10 project, the reverse engineering fails with NullReferenceException in Initialize() method.
The issue is specifically in EntityTypeConfiguration.t4 template. When I use only UseT4 without splitting, the problem won't occur.
Steps to reproduce:
- Create a new .NET 10 class library project
- Add Microsoft.EntityFrameworkCore.SqlServer (10.0.3) and Microsoft.EntityFrameworkCore.Design (10.0.3)
- Configure efpt.config.json with:
"UseT4": true,
"UseT4Split": true - Run "Reverse Engineer" from EF Core Power Tools
- Select any tables from the database
Your code
-- ============================================
-- SQL Script to reproduce EF Core Power Tools bug
-- Issue: NullReferenceException in EntityTypeConfiguration.t4
-- with UseT4Split on .NET 10 / EF Core 10.0.3
-- ============================================
-- Create test database
CREATE DATABASE EFCorePowerToolsTest;
GO
USE EFCorePowerToolsTest;
GO
-- ============================================
-- Table: PSW_ITEMS
-- ============================================
CREATE TABLE [dbo].[PSW_ITEMS] (
[ID] INT NOT NULL,
[ItemName] NVARCHAR(30) NOT NULL,
[ItemLabel] INT NOT NULL,
CONSTRAINT [PK_PSW_ITEMS] PRIMARY KEY CLUSTERED ([ID])
);
GO
-- ============================================
-- Table: PSW_ENTRY_POINTS
-- ============================================
CREATE TABLE [dbo].[PSW_ENTRY_POINTS] (
[IDEntryPoint] INT NOT NULL,
[EntryPointName] NVARCHAR(30) NOT NULL,
[DefaultLabelID] INT NULL,
[Comment] NVARCHAR(500) NULL,
CONSTRAINT [PK_PSW_ENTRY_POINTS] PRIMARY KEY CLUSTERED ([IDEntryPoint])
);
GO
-- ============================================
-- Table: PSW_ITEMS_ENTRY_POINTS (junction table)
-- ============================================
CREATE TABLE [dbo].[PSW_ITEMS_ENTRY_POINTS] (
[ID] INT IDENTITY(1,1) NOT NULL,
[ItemID] INT NULL,
[EntryPointID] INT NULL,
CONSTRAINT [PK_PSW_ITEMS_ENTRY_POINTS] PRIMARY KEY CLUSTERED ([ID]),
CONSTRAINT [FK_PSW_ITEMS_ENTRY_POINTS__ItemID__PSW_ITEMS]
FOREIGN KEY ([ItemID]) REFERENCES [dbo].[PSW_ITEMS] ([ID]),
CONSTRAINT [FK_PSW_ITEMS_ENTRY_POINTS__EntryPointID__PSW_ENTRY_POINTS]
FOREIGN KEY ([EntryPointID]) REFERENCES [dbo].[PSW_ENTRY_POINTS] ([IDEntryPoint])
);
GO
-- ============================================
-- Insert sample data (optional)
-- ============================================
INSERT INTO [dbo].[PSW_ITEMS] ([ID], [ItemName], [ItemLabel]) VALUES
(1, 'Item1', 100),
(2, 'Item2', 200);
INSERT INTO [dbo].[PSW_ENTRY_POINTS] ([IDEntryPoint], [EntryPointName], [DefaultLabelID], [Comment]) VALUES
(1, 'EntryPoint1', 100, 'Test entry point 1'),
(2, 'EntryPoint2', NULL, NULL);
INSERT INTO [dbo].[PSW_ITEMS_ENTRY_POINTS] ([ItemID], [EntryPointID]) VALUES
(1, 1),
(1, 2),
(2, 1);
GO
-- ============================================
-- Verify tables created
-- ============================================
SELECT 'Tables created successfully' AS Result;
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE';
GOStack traces
error : Error running transform: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.VisualStudio.TextTemplating55f740b0.GeneratedTextTransformation.Initialize()
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
--- End of inner exception stack trace ---
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Mono.TextTemplating.CompiledTemplate.TemplateProcessor.CreateAndProcess(ITextTemplatingEngineHost host, CompiledAssemblyData templateAssemblyData, String templateAssemblyFile, String fullName, CultureInfo culture, String[] referencedAssemblyFiles) in /_/Mono.TextTemplating/Mono.TextTemplating/CompiledTemplate.TemplateExecutor.cs:line 77
Microsoft.EntityFrameworkCore.Design.OperationException: Processing 'C:\SAW_Dev\TAW\SAW_COMMON\EntityData2\CodeTemplates\EFCore\EntityTypeConfiguration.t4' failed.
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.TextTemplatingModelGenerator.HandleErrors(TextTemplatingEngineHost host)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.TextTemplatingModelGenerator.GenerateModel(IModel model, ModelCodeGenerationOptions options)
at RevEng.Core.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions, Boolean removeNullableBoolDefaults, Boolean excludeNavigations, Boolean dbContextOnly, Boolean entitiesOnly, Boolean useSchemaFolders, Boolean useSchemaNamespaces) in D:\a\EFCorePowerTools\EFCorePowerTools\src\Core\RevEng.Core.80\ReverseEngineerScaffolder.cs:line 501
at RevEng.Core.ReverseEngineerScaffolder.GenerateDbContext(ReverseEngineerCommandOptions options, List`1 schemas, String outputContextDir, String modelNamespace, String contextNamespace, String projectPath, String outputPath, String rootNameSpace) in D:\a\EFCorePowerTools\EFCorePowerTools\src\Core\RevEng.Core.80\ReverseEngineerScaffolder.cs:line 93
at RevEng.Core.ReverseEngineerRunner.GenerateFiles(ReverseEngineerCommandOptions options) in D:\a\EFCorePowerTools\EFCorePowerTools\src\Core\RevEng.Core.80\ReverseEngineerRunner.cs:line 92
EF Core Power Tools version
2.6.1378
EF Core Power Tools CLI version
???
Database provider
Microsoft.EntityFrameworkCore.SqlServer
Target framework
.NET 10
IDE
Visual Studio 2026 18.3.1
Additional features in use
- T4 templates
- SQL Server .dacpac
- Handlebars template
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working