{"record":{"id":"f31d1aa0c66aa0ec","repo":"microsoft/aspire","slug":"the-maui-otlp-dev-tunnel-configuration-was-not-initialized-f31d1a","errorCode":null,"errorMessage":"The MAUI OTLP dev tunnel configuration was not initialized before endpoint allocation.","messagePattern":"The MAUI OTLP dev tunnel configuration was not initialized before endpoint allocation\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Maui/MauiOtlpExtensions.cs","lineNumber":194,"sourceCode":"\n                    if (dashboardOtlpEndpoint is null)\n                    {\n                        var exception = new DistributedApplicationException($\"The Aspire dashboard resource '{KnownResourceNames.AspireDashboard}' terminated or does not have a concrete OTLP endpoint named '{KnownEndpointNames.OtlpHttpEndpointName}' or '{KnownEndpointNames.OtlpGrpcEndpointName}', so the MAUI OTLP dev tunnel for resource '{parentBuilder.Resource.Name}' cannot start. Ensure dashboard OTLP ingestion is enabled, or configure an explicit OTLP endpoint URL.\");\n                        if (currentTunnelConfig.TryFailOtlpEndpointResolution(exception))\n                        {\n                            throw exception;\n                        }\n\n                        return;\n                    }\n\n                    await AllocateOtlpStubEndpointAsync(currentTunnelConfig, dashboardOtlpEndpoint.Value, evt.Services, appBuilder.Eventing, ct).ConfigureAwait(false);\n                }\n            });\n\n            appBuilder.Eventing.Subscribe<ResourceEndpointsAllocatedEvent>(async (evt, ct) =>\n            {\n                var currentTunnelConfig = tunnelConfig ?? throw new InvalidOperationException(\"The MAUI OTLP dev tunnel configuration was not initialized before endpoint allocation.\");\n                if (await TryResolveDashboardOtlpEndpointAsync(\n                    evt.Resource,\n                    evt.Services,\n                    waitForRuntimeSnapshot: false,\n                    currentTunnelConfig.RuntimeSnapshotResolutionTimeout,\n                    ct).ConfigureAwait(false) is { } dashboardOtlpEndpoint)\n                {\n                    await AllocateOtlpStubEndpointAsync(currentTunnelConfig, dashboardOtlpEndpoint, evt.Services, appBuilder.Eventing, ct).ConfigureAwait(false);\n                }\n            });\n        }\n        else\n        {\n            appBuilder.OnBeforeStart((evt, ct) =>\n                appBuilder.Eventing.PublishAsync(new ResourceEndpointsAllocatedEvent(stubResource, evt.Services), ct));\n        }\n\n        // Create dev tunnel with anonymous access for OTLP. The dynamic unresolved-endpoint guard above","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Maui/MauiOtlpExtensions.cs#L176-L212","documentation":"The ResourceEndpointsAllocatedEvent handler for the MAUI OTLP dev tunnel requires the same deferred tunnelConfig state. If endpoints are allocated before WithOtlpDevTunnel's initialization produced the configuration, the handler throws InvalidOperationException. It mirrors error 1137 but on the endpoint-allocation lifecycle event.","triggerScenarios":"ResourceEndpointsAllocatedEvent fires for a resource routed into this handler while tunnelConfig is still null at src/Aspire.Hosting.Maui/MauiOtlpExtensions.cs:194.","commonSituations":"Event-ordering problems where endpoint allocation precedes tunnel initialization; manually triggering endpoint allocation in tests; wiring WithOtlpDevTunnel after resources have started; multiple tunnels with mismatched names.","solutions":["Apply WithOtlpDevTunnel during app-model construction (before builder.Build()/Run), never after startup begins.","Confirm the endpoint-allocated resource is the MAUI-managed tunnel and not another resource leaking into the handler.","Avoid manually invoking endpoint allocation or reshaping resource startup order in tests or custom code.","Upgrade Aspire.Hosting.Maui if a known event-ordering race was fixed in a later version."],"exampleFix":"// before\napp.Start();\nmauiResource.WithOtlpDevTunnel(); // too late: endpoints already allocated\n// after\nmauiResource.WithOtlpDevTunnel();\napp.Start();","handlingStrategy":"validation","validationCode":"// ensure tunnel wiring precedes endpoint allocation events\nif (endpointsAllocated && !otlpTunnelWired) throw new InvalidOperationException(\"Apply WithOtlpDevTunnel before endpoints are allocated.\");","typeGuard":null,"tryCatchPattern":"try { await startAsync(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"not initialized before endpoint allocation\")) { /* wire WithOtlpDevTunnel earlier; don't force endpoint allocation */ }","preventionTips":["Apply WithOtlpDevTunnel before starting the AppHost","Avoid tests that raise ResourceEndpointsAllocatedEvent manually","Match tunnel resource names exactly as created by the extension","Check for version skew across Aspire.Hosting.Maui and core packages"],"tags":["maui","otlp","dev-tunnel","endpoint-allocation","race-condition"],"backgroundTag":"invalid-state-transition","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}