{"record":{"id":"c88135abfc3b0d56","repo":"dotnet/efcore","slug":"arraycreation-multi-dimensional-array-arraycrea","errorCode":null,"errorMessage":"ArrayCreation: multi-dimensional array: {arrayCreation}","messagePattern":"ArrayCreation: multi-dimensional array: (.+?)","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":236,"sourceCode":"            ? throw new InvalidOperationException($\"Argument with ref/out: {argument}\")\n            : Visit(argument.Expression, expectedType);\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 VisitArrayCreationExpression(ArrayCreationExpressionSyntax arrayCreation)\n    {\n        if (_semanticModel.GetTypeInfo(arrayCreation).Type is not IArrayTypeSymbol arrayTypeSymbol)\n        {\n            throw new InvalidOperationException($\"ArrayCreation: non-array type symbol: {arrayCreation}\");\n        }\n\n        if (arrayTypeSymbol.Rank > 1)\n        {\n            throw new NotImplementedException($\"ArrayCreation: multi-dimensional array: {arrayCreation}\");\n        }\n\n        var elementType = ResolveType(arrayTypeSymbol.ElementType);\n        Check.DebugAssert(elementType is not null);\n\n        return arrayCreation.Initializer is null\n            ? NewArrayBounds(elementType, Visit(arrayCreation.Type.RankSpecifiers[0].Sizes[0]))\n            : NewArrayInit(elementType, arrayCreation.Initializer.Expressions.Select(e => Visit(e)));\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 VisitBinaryExpression(BinaryExpressionSyntax binary)\n    {","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L218-L254","documentation":"`VisitArrayCreationExpression` throws `NotImplementedException` when `arrayTypeSymbol.Rank > 1` — multi-dimensional arrays (`int[,]`, `string[,,]`) are not supported by this translator or by LINQ expression trees generally. Only single-dimensional arrays (`int[]`) translate.","triggerScenarios":"A precompiled query containing a rectangular/multi-dimensional array literal, e.g. `new int[2, 3] { ... }` or passing a `T[,]` constant into the query.","commonSituations":"Migrating numerical/matrix code or interop helpers that use `[,]` arrays into a query that gets precompiled.","solutions":["Replace the multi-dimensional array with a jagged array (`int[][]`) or a flat `int[]` plus index math.","Hoist the data out of the query and pass it in as a captured, single-dimensional structure."],"exampleFix":"// before\nvar grid = new int[2, 3];\nvar q = ctx.X.Where(x => lookup(grid, x));\n// after\nvar grid = new int[2][];   // jagged\nvar q = ctx.X.Where(x => lookup(grid, x));","handlingStrategy":"validation","validationCode":"// Reject multi-dimensional arrays up front.\nvar arrayType = semanticModel.GetTypeInfo(arrayCreationNode).Type as IArrayTypeSymbol;\nif (arrayType is { Rank: > 1 })\n    throw new NotSupportedException(\"Multi-dimensional arrays are not supported in precompiled queries; use a jagged array.\");\n\ntranslator.Translate(arrayCreationNode, semanticModel);","typeGuard":null,"tryCatchPattern":"try { translator.Translate(node, semanticModel); }\ncatch (NotImplementedException ex) when (ex.Message.Contains(\"multi-dimensional array\"))\n{ /* convert to jagged array and rebuild */ }","preventionTips":["Use single-dimensional or jagged arrays (`T[][]`) instead of `T[,]` in queries.","Avoid passing matrix/grid data structures into precompiled query expressions."],"tags":["ef-core","precompiled-queries","expression-trees","unsupported-construct","arrays"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}