{"record":{"id":"36c785b8b61002b4","repo":"microsoft/aspire","slug":"could-not-resolve-runtime-type-fullname","errorCode":null,"errorMessage":"Could not resolve runtime type '{fullName}'.","messagePattern":"Could not resolve runtime type '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.RemoteHost/Ats/ReferenceExpressionRef.cs","lineNumber":384,"sourceCode":"    {\n        var referenceExpressionType = GetRequiredHostingType(HostingTypeNames.ReferenceExpression, condition);\n        var valueProviderType = GetRequiredHostingType(HostingTypeNames.ValueProviderInterface, condition);\n\n        var createConditionalMethod = referenceExpressionType.GetMethod(\n            \"CreateConditional\",\n            BindingFlags.Public | BindingFlags.Static,\n            binder: null,\n            [valueProviderType, typeof(string), referenceExpressionType, referenceExpressionType],\n            modifiers: null)\n            ?? throw new InvalidOperationException($\"'{referenceExpressionType.FullName}' is missing CreateConditional(...).\");\n\n        return createConditionalMethod.Invoke(null, [condition, matchValue, whenTrue, whenFalse])\n            ?? throw new InvalidOperationException($\"'{referenceExpressionType.FullName}.CreateConditional(...)' returned null.\");\n    }\n\n    private static Type GetRequiredHostingType(string fullName, object? anchor = null) =>\n        FindHostingType(fullName, anchor) ??\n        throw new InvalidOperationException($\"Could not resolve runtime type '{fullName}'.\");\n\n    private static Type? FindHostingType(string fullName, object? anchor = null)\n    {\n        if (anchor is not null)\n        {\n            var anchoredType = anchor.GetType().Assembly.GetType(fullName, throwOnError: false);\n            if (anchoredType is not null)\n            {\n                return anchoredType;\n            }\n        }\n\n        foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())\n        {\n            var type = assembly.GetType(fullName, throwOnError: false);\n            if (type is not null)\n            {\n                return type;","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.RemoteHost/Ats/ReferenceExpressionRef.cs#L366-L402","documentation":"GetRequiredHostingType resolves a required Aspire.Hosting runtime type (ReferenceExpression, IValueProvider, ReferenceExpression.Builder) by full name, first from the anchor object's assembly and then across loaded assemblies. If no loaded assembly exports a type with that exact full name, this InvalidOperationException is thrown. It signals the ATS remote host could not find the hosting type it needs, usually because no Aspire.Hosting assembly (or a wrong-version one) is loaded in the app domain.","triggerScenarios":"CreateConditionalReferenceExpression (or CreateReferenceExpressionBuilder and friends) calls GetRequiredHostingType('Aspire.Hosting.ApplicationModel.ReferenceExpression' / '.IValueProvider' / '.ReferenceExpression+Builder') while the remote-host process has no Aspire.Hosting assembly loaded, or the loaded copy has renamed/moved the type (namespace changes across major versions).","commonSituations":"Remote-host binary/apphost server mismatched with integration assemblies on disk (the documented 'LoaderExceptions' scenario); running an app built against a different Aspire major version; Aspire.Hosting.dll failing to load due to missing dependencies so its types never appear.","solutions":["Ensure Aspire.Hosting (and the referenced app model types) is restored and actually loaded by the apphost — check the apphost server log for LoaderExceptions Warnings.","Align Aspire SDK/CLI version with the Aspire.* package versions and rebuild from a clean bin/obj.","Verify the exact full type name still exists in the loaded Aspire.Hosting.dll (namespace moves across versions break the lookup).","If assemblies are probed from custom paths, confirm the probe/manifest paths point at the restored Aspire.Hosting.dll."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// resolve required hosting types before calling remote-host ATS APIs\nvar refExprType = Type.GetType(\"Aspire.Hosting.ApplicationModel.ReferenceExpression, Aspire.Hosting\", throwOnError: false);\nvar valueProviderType = Type.GetType(\"Aspire.Hosting.ApplicationModel.IValueProvider, Aspire.Hosting\", throwOnError: false);\nif (refExprType is null || valueProviderType is null)\n    throw new InvalidOperationException(\"Aspire.Hosting assembly is not loaded or is the wrong version.\");","typeGuard":"static bool HostingTypesAvailable() =>\n    Type.GetType(\"Aspire.Hosting.ApplicationModel.ReferenceExpression, Aspire.Hosting\", throwOnError: false) is not null;","tryCatchPattern":"try { var result = ToConditionalReferenceExpression(args); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Could not resolve runtime type\"))\n{ log.LogError(ex, \"Hosting type missing; check Aspire.Hosting loading\"); throw; }","preventionTips":["Ensure Aspire.Hosting is referenced and loads in the remote-host process.","Match the bundled apphost server version to integration assemblies.","Watch apphost server logs for LoaderExceptions after dependency changes."],"tags":["reflection","type-resolution","aspire-hosting","assembly-loading"],"backgroundTag":"class-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}