Skip to main content

Posts

Showing posts with the label Aspire

.NET Aspire: The price of forgetting WithReference

Recently I lost way more time than I'd like to admit on an error that turned out to be one missing line of code. The symptom looked like a networking problem. The cause was a missing WithReference call in my Aspire AppHost. Here's the exception my proxy threw the moment it tried to forward a request to my API: System.Net.Http.HttpRequestException: No such host is known. (api:443) ---> System.Net.Sockets.SocketException (11001): No such host is known. at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.HttpConnectionPool....

YARP and Aspire: "https+http scheme is not supported"

Recently I was wiring up a YARP reverse proxy in front of a couple of Aspire-managed services: an API and an Angular frontend. Aspire gives you service discovery for free, so the obvious move is to point your YARP clusters at the logical service names instead of hardcoded URLs. My first attempt looked like this: "Clusters": { "api-cluster": { "Destinations": { "api-destination": { "Address": "https+http://api" } } }, "frontend-cluster": { "Destinations": { "frontend-destination": { "Address": "https+http://angular-frontend" } } } } The https+http:// scheme is the standard Aspire service discovery convention: try HTTPS first, fall back to HTTP. It works fine when you're resolving endpoints through HttpClient . Unfortunately YARP doesn’t like this configuration. After setting it up with these values ...

Fixing the "Newer version of Aspire.Hosting.AppHost required" error

After pulling some NuGet packages into my .NET Aspire project, I ran into this cryptic startup failure: Aspire.Hosting.DistributedApplicationException: Newer version of the Aspire.Hosting.AppHost package is required to run the application. Ensure you are referencing at least version '13.2.2'. at Aspire.Hosting.Dcp.DcpDependencyCheck.EnsureDcpVersion(DcpInfo dcpInfo) at Aspire.Hosting.Dcp.DcpDependencyCheck.GetDcpInfoAsync(...) at Aspire.Hosting.Dcp.DcpHost.StartAsync(...) The app host refuses to start, and the logs point you toward a version check deep inside DCP internals. The error message tells me that a minimum version of the hosting package is required,but no matter how many times I ran dotnet restore or update NuGet packages through Visual Studio, the error persists. That's because there are two places that pin the Aspire version. Why updating NuGet packages isn't enough Aspire AppHost projects use a special SDK reference at the very...

Showing custom metrics in Aspire

After enabling Aspire for your application, you get OpenTelemetry integration for free thanks to the included ServiceDefaults code.  This will setup OpenTelemetry using a set of defaults: Unfortunately this default configuration didn’t pick up any of the custom metrics I added. I first thought that this meant that I couldn’t use the service defaults anymore and configure the OpenTelemetry integration manually. But then I discovered that you can change/extend the default configuration in a specific project by using the ConfigureOpenTelemetryTracerProvider and/or ConfigureOpenTelemetryMeterProvider methods. Add your custom OpenTelemetry configuration after calling the Aspire builder.AddServiceDefaults() : Now our custom metrics appear nicely in the Aspire dashboard: More information Welcome to Aspire | Aspire Enabling .NET Aspire for an existing solution Replacing EventCounters with the new Metrics API

.NET Aspire error - Aspire.Hosting.DistributedApplicationException: 'Failed to get effective launch profile for project resource ''.

I’m currently working on 'Aspirifying' (don't know if that is a correct verb' multiple applications. After enabling Aspire for one application, the Aspire Host failed to launch with the following error message: Aspire.Hosting.DistributedApplicationException: 'Failed to get effective launch profile for project resource ' '. There is malformed JSON in the project's launch settings file at 'C:\projects\<ProjectName> \Properties\launchSettings.json'.' The inner exception gave some extra details: JsonException: The JSON value could not be converted to System.Nullable`1[System.Boolean]. Path: $.profiles[‘<ProjectName>.API'].dotnetRunMessages | LineNumber: 21 | BytePositionInLine: 33. I opened up the mentioned launchSettings.json file: The culprit is the dotnetRunMessages setting where instead of a 'true' string, we should specify a boolean value: No idea where this setting is coming from, but I certainly never ...

Compiler error ASPIRE007 after upgrading Aspire

After upgrading the .NET Aspire NuGet packages to the latest version on one of my projects, I started to get the following compiler error: 'Project' requires a reference to "Aspire.AppHost.Sdk" with version "9.0.0" or greater to work correctly. Please add the following line after the Project declaration <Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" /> . The error message is self explanatory and clearly defines how we could fix this. Add the Sdk reference to your csproj file to get rid of this compiler error: The strange thing was that after applying the upgrade on one branch, I also started to get the same compiler error on other branches although the Aspire NuGet were not (yet) upgraded on these branches. Bizar! More information Compiler Error ASPIRE007 - .NET Aspire | Microsoft Learn

.NET Aspire Dashboard - The mystery of the hidden endpoint

One of the cool features of .NET Aspire is the Aspire Dashboard(also available standalone by the way). It allows you to closely track various aspects of your app and its resources, including logs, traces, and environment configurations, in real-time. After migrating an existing solution to .NET Aspire, I noticed that no URL was shown for some of the endpoints: I couldn’t find a direct reason why this was the case, but I found online that it could be related to the launchsettings.json files. Here is the launchsettings.json file for the ‘api’ project (where the endpoint URL is shown): And here is the launchsettings.json file the for the ‘webapp’ project (where no endpoint is shown): With some trial and error, I found that the order of the profiles in the launchsettings.json file matters and that Aspire will use the first profile found. I switched the profiles for the ‘webapp’ project: And indeed, after doing that, the endpoint URL became visible on the dashboard: ...

Enabling .NET Aspire for an existing solution

I hope that you already had a change to try .NET Aspire, a comprehensive set of tools, templates, and packages designed to help developers build observable, production-ready applications. It enhances the development experience by providing dev-time orchestration, integrations with commonly used services, and robust tooling support. .The goal is to simplify the management of multi-project applications, container resources, and other dependencies, making it easier to develop interconnected apps. To make it even better, it includes features like service discovery, connection string management, and environment variable configuration, streamlining the setup process for local development environments. And if that couldn’t convince you yet, than maybe the Aspire Dashboard will. Sounds great right? Reason enough to add it to your existing projects if you are not using it yet. A great tutorial exists on Microsoft Learn to help you add it to your existing projects. Unfortunately I had a ...

.NET Aspire Developers Day is coming up!

If you are part of the .NET community, you certainly have heard about .NET Aspire. It is a new framework/tool/set of patterns from Microsoft that allows you to build observable, cloud ready distributed applications. It’s main goal is to make it easier to build cloud-native applications on top of .NET. Now if you didn’t had the time yet to take a look at .NET Aspire and want to learn what all the fuzz is about, I have some good news for you. On July 23, Microsoft will host the .NET Aspire Developers Day. This livestream event will be a full day of sessions with one common goal: To show you how easy it is to harness the power of .NET Aspire, why it’s essential for modern development, and how you can leverage a vibrant community for support and innovation. If you like to join, subscribe here for the event. Hope to see you all(virtually) there! In preparation of the event, you can watch the recording of the Let’s Learn .NET Aspire beginner series: More information .NET A...

Failed to start Dapr - file does not exist

A short post today; I’ll share an issue a encountered when trying to run a Dapr enabled application. This blog post wouldn’t add much value if I didn’t share a solution as well. Let me first start by refreshing your memory if you have no clue what Dapr is about. Feel free to skip this intro and move on to the next part if you already tried Dapr before. Introducing Dapr On their website, Dapr is described as: APIs for Building Secure and Reliable Microservices I don’t think that is the best description, but if you search deeper in the documentation, you find the following description: Dapr is a portable, event-driven runtime that makes it easy for any developer to build resilient, stateless, and stateful applications that run on the cloud and edge and embraces the diversity of languages and developer frameworks. That describes it perfectly! Want to know more? Check out this video: The issue… One of the nice features of Dapr is that you can use the Dapr C...