{"record":{"id":"939d74df7bbdb199","repo":"microsoft/aspire","slug":"resource-resourcename-not-found","errorCode":null,"errorMessage":"Resource '{resourceName}' not found.","messagePattern":"Resource '(.+?)' not found\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Testing/DistributedApplicationHostingTestingExtensions.cs","lineNumber":259,"sourceCode":"    /// <param name=\"networkIdentifier\">The optional network identifier string. If none is specified, the default network is used.</param>\n    /// <param name=\"endpointName\">The optional endpoint name. If none is specified, the \"https\" endpoint is preferred when available, falling back to \"http\".</param>\n    /// <returns>A URI representation of the endpoint.</returns>\n    /// <exception cref=\"ArgumentException\">The resource was not found, no matching endpoint was found, or multiple endpoints were found.</exception>\n    /// <exception cref=\"InvalidOperationException\">The resource has no endpoints.</exception>\n    [AspireExport]\n    internal static Uri GetEndpointForNetworkExport(this DistributedApplication app, string resourceName, string? networkIdentifier = default, string? endpointName = default)\n    {\n        return app.GetEndpointForNetwork(resourceName, networkIdentifier is null ? null : new NetworkIdentifier(networkIdentifier), endpointName);\n    }\n\n    static IResource GetResource(DistributedApplication app, string resourceName)\n    {\n        ThrowIfNotStarted(app, Properties.Resources.ApplicationNotStartedExceptionMessage);\n        var applicationModel = app.Services.GetRequiredService<DistributedApplicationModel>();\n\n        if (!applicationModel.Resources.TryGetByName(resourceName, out var resource))\n        {\n            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ResourceNotFoundExceptionMessage, resourceName), nameof(resourceName));\n        }\n\n        return resource;\n    }\n\n    static string GetEndpointUriStringCore(DistributedApplication app, string resourceName, string? endpointName = default, NetworkIdentifier? networkIdentifier = default)\n    {\n        var resource = GetResource(app, resourceName);\n        if (resource is not IResourceWithEndpoints resourceWithEndpoints)\n        {\n            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ResourceHasNoAllocatedEndpointsExceptionMessage, resourceName), nameof(resourceName));\n        }\n\n        EndpointReference? endpoint;\n        if (!string.IsNullOrEmpty(endpointName))\n        {\n            endpoint = GetEndpointOrDefault(resourceWithEndpoints, endpointName, networkIdentifier);\n        }","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Testing/DistributedApplicationHostingTestingExtensions.cs#L241-L277","documentation":"GetResource throws this ArgumentException when no resource with the given name exists in the DistributedApplicationModel. The lookup uses the model's name-based resource collection (TryGetByName) and fails fast when the name doesn't match any registered resource.","triggerScenarios":"Calling app.GetResource(\"name\") (or GetConnectionStringAsync/GetEndpointAsync which call it) with a name that doesn't match any resource in the app model — wrong name, wrong casing, or resource added under a different name.","commonSituations":"Typo in resource name; renames of AddXxx calls not propagated to tests; adding resources conditionally (e.g. only in publish mode) so tests can't find them; case-sensitivity mismatches.","solutions":["Verify the exact resource name as passed to AddXxx in the AppHost, including casing","List app.Services.GetRequiredService<DistributedApplicationModel>().Resources to see valid names","Ensure the resource isn't added conditionally for the test's execution context"],"exampleFix":"// before\nvar redis = app.GetResource(\"cache\"); // actual name \"redis\"\n// after\nvar redis = app.GetResource(\"redis\");","handlingStrategy":"validation","validationCode":"var model = app.Services.GetRequiredService<DistributedApplicationModel>();\nbool exists = model.Resources.Any(r => string.Equals(r.Name, name, StringComparison.OrdinalIgnoreCase));","typeGuard":null,"tryCatchPattern":"try { var resource = app.GetResource(name); }\ncatch (ArgumentException)\n{\n    // name doesn't match any model resource; list resources to debug\n}","preventionTips":["Copy resource names directly from AppHost AddXxx calls","Beware conditional resource registration in publish vs run mode","Resource names are case-sensitive for lookup — keep them consistent"],"tags":["aspire","testing","resource-not-found","argument"],"backgroundTag":"resource-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"}