{"record":{"id":"dd2a81dfd54205ff","repo":"litedb-org/LiteDB","slug":"constructor-for-node-type-name-are-not-supported","errorCode":null,"errorMessage":"Constructor for {node.Type.Name} are not supported when convert to BsonExpression ({node.ToString()}).","messagePattern":"Constructor for (.+?) are not supported when convert to BsonExpression \\((.+?)\\)\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs","lineNumber":360,"sourceCode":"            {\n                base.VisitUnary(node);\n            }\n\n            return node;\n        }\n\n        /// <summary>\n        /// Visit :: x => `new { x.Id, x.Name }`\n        /// </summary>\n        protected override Expression VisitNew(NewExpression node)\n        {\n            if (node.Members == null)\n            {\n                if (TryGetResolver(node.Type, out var type))\n                {\n                    var pattern = type.ResolveCtor(node.Constructor);\n\n                    if (pattern == null) throw new NotSupportedException($\"Constructor for {node.Type.Name} are not supported when convert to BsonExpression ({node.ToString()}).\");\n\n                    this.ResolvePattern(pattern, null, node.Arguments);\n                }\n                else\n                {\n                    throw new NotSupportedException($\"New instance are not supported for {node.Type} when convert to BsonExpression ({node.ToString()}).\");\n                }\n            }\n            else\n            {\n                _builder.Append(\"{ \");\n\n                for (var i = 0; i < node.Members.Count; i++)\n                {\n                    var member = node.Members[i];\n                    _builder.Append(i > 0 ? \", \" : \"\");\n                    _builder.AppendFormat(\"'{0}': \", member.Name);\n                    this.Visit(node.Arguments[i]);","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs#L342-L378","documentation":"Thrown by VisitNew when a new SomeType(args) expression is encountered, SomeType has a registered ITypeResolver, but ResolveCtor returns null for the constructor used. The type is recognized by the resolver system, but the specific constructor overload has no translation pattern.","triggerScenarios":"Using new with a resolver-backed type and a constructor the resolver does not support. For example new DateTime(2020, 1, 1, 12, 0, 0, DateTimeKind.Utc) if DateTimeResolver does not have a pattern for that 6-argument overload, or new Guid(byteArray) if GuidResolver lacks that ctor.","commonSituations":"Using an uncommon constructor overload of a built-in type in a LINQ query predicate or projection. Passing calendar/timezone arguments that the resolver does not map.","solutions":["Use a supported constructor overload for the type (check the resolver source for recognized ctors).","Hoist the value into a closure variable so the visitor evaluates it in memory instead of translating the constructor.","Use a raw BsonExpression or a pre-computed constant."],"exampleFix":"// before\ncol.Find(x => x.CreatedAt > new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc));\n// unsupported DateTime ctor overload\n\n// after -- hoist the constant\nvar cutoff = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);\ncol.Find(x => x.CreatedAt > cutoff);","handlingStrategy":"validation","validationCode":"// Hoist new SomeType(args) into a closure variable so it is evaluated in memory\nvar cutoff = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc); // evaluate outside\ncol.Find(x => x.CreatedAt > cutoff);","typeGuard":null,"tryCatchPattern":"try\n{\n    var results = col.Find(x => x.CreatedAt > new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc));\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Constructor for\"))\n{\n    var cutoff = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);\n    results = col.Find(x => x.CreatedAt > cutoff);\n}","preventionTips":["Avoid constructing resolver-backed types (DateTime, Guid, etc.) inline in LINQ queries; hoist them into closure variables.","Use the simplest constructor overload if inline construction is unavoidable.","Write unit tests for each predicate to catch unsupported constructors early."],"tags":["linq","constructor","resolver"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}