{"record":{"id":"23acd1457b4085d7","repo":"dotnet/efcore","slug":"arraycreation-non-array-type-symbol-implicitarr","errorCode":null,"errorMessage":"ArrayCreation: non-array type symbol: {implicitArrayCreation}","messagePattern":"ArrayCreation: non-array type symbol: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":472,"sourceCode":"                            localSymbol.Name,\n                            localSymbol.NullableAnnotation is NullableAnnotation.NotAnnotated)));\n        }\n\n        throw new InvalidOperationException(\n            $\"Encountered unknown identifier name '{identifierName}', which doesn't correspond to a lambda parameter or captured variable\");\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public override Expression VisitImplicitArrayCreationExpression(ImplicitArrayCreationExpressionSyntax implicitArrayCreation)\n    {\n        if (_semanticModel.GetTypeInfo(implicitArrayCreation).Type is not IArrayTypeSymbol arrayTypeSymbol)\n        {\n            throw new InvalidOperationException($\"ArrayCreation: non-array type symbol: {implicitArrayCreation}\");\n        }\n\n        if (arrayTypeSymbol.Rank > 1)\n        {\n            throw new NotImplementedException($\"ArrayCreation: multi-dimensional array: {implicitArrayCreation}\");\n        }\n\n        var elementType = ResolveType(arrayTypeSymbol.ElementType);\n        Check.DebugAssert(elementType is not null);\n\n        var initializers = implicitArrayCreation.Initializer.Expressions.Select(e => Visit(e));\n\n        return NewArrayInit(elementType, initializers);\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L454-L490","documentation":"Thrown by VisitImplicitArrayCreationExpression when translating an implicit array literal (new[] { ... }) but Roslyn's semantic model reports a type that is not an IArrayTypeSymbol. The translator can only build a NewArrayInit expression for a genuine single-dimensional array type, so a non-array (or null) type symbol is an internal inconsistency it cannot proceed from.","triggerScenarios":"An implicit array creation expression (e.g. new[] { a, b }) appears inside a precompiled query, and _semanticModel.GetTypeInfo(node).Type is null or not an IArrayTypeSymbol. Typically a malformed/inferred array literal whose element type failed to resolve, or an edge case in generic array inference.","commonSituations":"Rare and usually not reachable with normal user code; indicates either a translator bug or an unusual array literal whose inferred element type is an error/unresolved type (e.g. new[] { unresolvedVar, 1 }).","solutions":["Give the array literal an explicit element type: new int[] { ... } instead of new[] { ... }","Hoist the array out of the precompiled query into a local variable captured by the query","If it reproduces with trivial code, report it as an EF Core precompiled-queries bug with a minimal repro"],"exampleFix":"// before\nvar q = ctx.Blogs.Where(b => new[] { b.Id }.Contains(b.Id));\n// after (explicit type + hoisted)\nvar ids = new int[] { 1, 2 };\nvar q = ctx.Blogs.Where(b => ids.Contains(b.Id));","handlingStrategy":"validation","validationCode":"// Before precompiling, ensure all array literals in the query have a resolvable element type.\n// Prefer explicit element types over 'new[]'.\nvar ok = queryExpr.ToString(); // if this contains \"new[]\", review each occurrence\n// Static check: warn on implicit array creation in precompiled query source.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use explicit element types (new int[] { ... }) instead of implicit new[] in precompiled queries","Hoist array construction out of the query body into captured locals","Keep precompiled query bodies free of constructs that depend on type inference edge cases"],"tags":["efcore","precompiled-queries","roslyn","arrays","csharp"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}