{"record":{"id":"b3469ec4fe6afff2","repo":"dotnet/efcore","slug":"could-not-resolve-type-symbol-for-parameter-type","errorCode":null,"errorMessage":"Could not resolve type symbol for: {parameter.Type}","messagePattern":"Could not resolve type symbol for: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":193,"sourceCode":"\n        var parameterInfos = new ParameterInfo[parameters.Length];\n        var memberInfos = new MemberInfo[parameters.Length];\n        var arguments = new Expression[parameters.Length];\n\n        foreach (var initializer in anonymousObjectCreation.Initializers)\n        {\n            // If the initializer's name isn't explicitly specified, infer it from the initializer's expression like the compiler does\n            var name = initializer.NameEquals is not null\n                ? initializer.NameEquals.Name.Identifier.Text\n                : initializer.Expression is MemberAccessExpressionSyntax memberAccess\n                    ? memberAccess.Name.Identifier.Text\n                    : throw new InvalidOperationException(\n                        $\"AnonymousObjectCreation: unnamed initializer with non-MemberAccess expression: {initializer.Expression}\");\n\n            var position = Array.FindIndex(parameters, p => p.Name == name);\n            var parameter = parameters[position];\n            var parameterType = ResolveType(parameter.Type)\n                ?? throw new InvalidOperationException(\n                    \"Could not resolve type symbol for: \" + parameter.Type);\n\n            parameterInfos[position] = new FakeParameterInfo(name, parameterType, position);\n            arguments[position] = Visit(initializer.Expression);\n            memberInfos[position] = anonymousType.GetProperty(parameter.Name)!;\n        }\n\n        return New(\n            new FakeConstructorInfo(anonymousType, parameterInfos),\n            arguments: arguments,\n            memberInfos);\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.","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L175-L211","documentation":"While translating an anonymous-object initializer, `ResolveType(parameter.Type)` returns null for one of the constructor parameters and the translator throws `InvalidOperationException`. `ResolveType` fails when the Roslyn type symbol cannot be mapped to a CLR `Type` (assembly not loaded / not referenced).","triggerScenarios":"An anonymous projection (`new { ... }`) in a precompiled query where one of the projected member's types lives in an assembly that the translator cannot resolve via the compilation or the `additionalAssembly` hint.","commonSituations":"The entity/value type referenced by the projected member is in a separate assembly not passed as `additionalAssembly`, or the compilation is missing that reference.","solutions":["Add a metadata reference for the assembly containing the type to the compilation.","Pass that assembly via the `additionalAssembly` argument of `Load` (used as a fallback in `GetClrTypeFromAssembly`).","Project a type that is already resolvable from the referenced assemblies."],"exampleFix":"// before\ntranslator.Load(compilation, dbContext);   // member type in Other.dll unresolved\n// after\ntranslator.Load(compilation, dbContext, additionalAssembly: typeof(OtherType).Assembly);","handlingStrategy":"validation","validationCode":"// Pre-resolve all anonymous-member types against the additional assembly.\nforeach (var init in anon.Initializers)\n{\n    var typeInfo = semanticModel.GetTypeInfo(init.Expression).Type;\n    if (typeInfo is null\n        || (additionalAssembly?.GetType(typeInfo.ToDisplayString()) is null\n            && Type.GetType(typeInfo.ToDisplayString()) is null))\n        throw new InvalidOperationException(\n            $\"Projected member type {typeInfo} cannot be resolved; add it to the compilation or additionalAssembly.\");\n}","typeGuard":null,"tryCatchPattern":"try { translator.Translate(node, semanticModel); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Could not resolve type symbol for:\"))\n{ /* add the referenced assembly and retry */ }","preventionTips":["Pass every assembly referenced by projected types via `additionalAssembly`.","Keep entity/value types in assemblies available at translation time.","Project simple, fully-referenced types in precompiled queries."],"tags":["ef-core","precompiled-queries","roslyn","type-resolution"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}