<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/net-aspire-the-price-of-forgetting-withreference-ivluyvzfp" -->

---
title: .NET Aspire: The price of forgetting WithReference
description: A common but easy-to-miss mistake in .NET Aspire: forgetting to call WithReference() when wiring up services in the AppHost. Without it, environment variables...
canonical: https://daily.dev/posts/net-aspire-the-price-of-forgetting-withreference-ivluyvzfp
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: .NET Aspire: The price of forgetting WithReference | daily.dev
og:description: A common but easy-to-miss mistake in .NET Aspire: forgetting to call WithReference() when wiring up services in the AppHost. Without it, environment variables...
og:url: https://daily.dev/posts/net-aspire-the-price-of-forgetting-withreference-ivluyvzfp
og:image: https://api.daily.dev/og/posts/IVluYVzFP.png
og:image:alt: .NET Aspire: The price of forgetting WithReference
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# .NET Aspire: The price of forgetting WithReference

**[The Art of Simplicity](https://daily.dev/sources/bartwullems)** · 3 min read · 14 upvotes · 1 comments

## Summary

A common but easy-to-miss mistake in .NET Aspire: forgetting to call WithReference() when wiring up services in the AppHost. Without it, environment variables for service endpoints are never injected, so YARP's service discovery can't resolve logical names like 'api' to real URLs. The result is a confusing SocketException that looks like a DNS or networking failure. The fix is a single line — adding .WithReference(api) to the proxy's builder chain. Key takeaway: service discovery in Aspire is opt-in per reference; adding a project to the AppHost does not automatically expose its endpoints to other resources.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://bartwullems.blogspot.com/2026/07/net-aspire-price-of-forgetting.html>

## Questions this post answers

### Why does my YARP proxy in a .NET Aspire app throw 'No such host is known' for a resource name like api?

This happens when the WithReference call is missing in the Aspire AppHost. WithReference injects environment variables such as services__api__https__0 that let the .NET service discovery middleware resolve a logical resource name like api into a real https://localhost:xxxxx address. Without it, .NET treats api as a literal hostname, DNS lookup fails, and YARP throws a SocketException disguised as an HTTP error.

_daily.dev surfaces debugging writeups like this for developers wiring up Aspire and YARP service discovery._

### Does WaitFor(api) in .NET Aspire also enable service discovery for that resource?

No, WaitFor only controls startup ordering, ensuring one resource starts after another is ready. It does not inject the environment variables needed for service discovery. Only WithReference(api) exposes a resource's endpoint URLs to the referencing project; adding a project to the AppHost or calling WaitFor does not automatically expose its endpoints to other resources.

_Developers troubleshooting Aspire resource wiring can find these distinctions clarified through daily.dev._

## Community discussion

Top comments from developers on daily.dev.

**@minhtetaung** · 0 upvotes

> ![GIF](https://static.klipy.com/ii/35ccce3d852f7995dd2da910f2abd795/9f/a7/Uen1Div0.gif)

## Similar posts on daily.dev

- [YARP and Aspire: "https\+http scheme is not supported"](https://daily.dev/posts/yarp-and-aspire-https-http-scheme-is-not-supported--ao9iptakh) · The Art of Simplicity · 5 upvotes · 0 comments
- [How to Improve Developer Experience in Microservices Applications with .NET Aspire](https://daily.dev/posts/how-to-improve-developer-experience-in-microservices-applications-with-net-aspire-o3dcliqyw) · freeCodeCamp · 6 upvotes · 0 comments
- [Running a production-like local environment with Aspire](https://daily.dev/posts/running-a-production-like-local-environment-with-aspire-7qzdip0aa) · Tim Deschryver · 0 upvotes · 0 comments

---

Tags: [#architecture](https://daily.dev/tags/architecture), [#.net](https://daily.dev/tags/.net)

[View this post on daily.dev](https://daily.dev/posts/net-aspire-the-price-of-forgetting-withreference-ivluyvzfp)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":".NET Aspire: The price of forgetting WithReference","url":"https://daily.dev/posts/net-aspire-the-price-of-forgetting-withreference-ivluyvzfp","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/net-aspire-the-price-of-forgetting-withreference-ivluyvzfp"},"datePublished":"2026-07-28T05:43:39.408Z","dateModified":"2026-09-13T21:20:10.307Z","description":"A common but easy-to-miss mistake in .NET Aspire: forgetting to call WithReference() when wiring up services in the AppHost. Without it, environment variables...","image":"https://media.daily.dev/image/upload/s--foaA6JGU--/f_auto/v1722860399/public/Placeholder%2004","thumbnailUrl":"https://media.daily.dev/image/upload/s--foaA6JGU--/f_auto/v1722860399/public/Placeholder%2004","isAccessibleForFree":true,"articleSection":"The Art of Simplicity","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"The Art of Simplicity","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/52b68c70636d44f0901ae7cd107c9438","url":"https://daily.dev/sources/bartwullems"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/net-aspire-the-price-of-forgetting-withreference-ivluyvzfp","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":14},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"architecture,.net","timeRequired":"PT3M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"The Art of Simplicity","item":"https://daily.dev/sources/bartwullems"},{"@type":"ListItem","position":3,"name":".NET Aspire: The price of forgetting WithReference"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/net-aspire-the-price-of-forgetting-withreference-ivluyvzfp","comment":[{"@type":"Comment","text":"","datePublished":"2026-07-30T07:13:30.072Z","url":"https://daily.dev/posts/IVluYVzFP#c-MBze2VYLn","author":{"@type":"Person","name":"Min Htet Aung","url":"https://daily.dev/minhtetaung","image":"https://lh3.googleusercontent.com/a/ACg8ocJA37-XiGWIuxivFuog6jr0bND48U5KC4IeVin3_mYaIoQ=s96-c"}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/net-aspire-the-price-of-forgetting-withreference-ivluyvzfp#faq","mainEntity":[{"@type":"Question","name":"Why does my YARP proxy in a .NET Aspire app throw 'No such host is known' for a resource name like api?","acceptedAnswer":{"@type":"Answer","text":"This happens when the WithReference call is missing in the Aspire AppHost. WithReference injects environment variables such as services__api__https__0 that let the .NET service discovery middleware resolve a logical resource name like api into a real https://localhost:xxxxx address. Without it, .NET treats api as a literal hostname, DNS lookup fails, and YARP throws a SocketException disguised as an HTTP error. daily.dev surfaces debugging writeups like this for developers wiring up Aspire and YARP service discovery."}},{"@type":"Question","name":"Does WaitFor(api) in .NET Aspire also enable service discovery for that resource?","acceptedAnswer":{"@type":"Answer","text":"No, WaitFor only controls startup ordering, ensuring one resource starts after another is ready. It does not inject the environment variables needed for service discovery. Only WithReference(api) exposes a resource's endpoint URLs to the referencing project; adding a project to the AppHost or calling WaitFor does not automatically expose its endpoints to other resources. Developers troubleshooting Aspire resource wiring can find these distinctions clarified through daily.dev."}}]}
```

