0
Detect whether API failures come from your .NET contract logic or the container environment running it.
Added May 26, 2026
9 signals
NET teams are trying to standardize API behavior with OpenAPI, ProblemDetails, and result patterns, while also relying on Docker-based development and test environments. When container DNS or networking breaks, API tests, docs, and middleware validation can fail in misleading ways, wasting time across backend and platform teams.
API teams increasingly develop, test, and document .NET services inside containerized local and CI environments, but API error contracts and runtime infrastructure failures are treated separately. When Docker networking or DNS breaks, developers often see it first as confusing API test failures, bad generated docs, or inconsistent ProblemDetails responses rather than an environment regression.
Detailed solution approach available for premium members.
Market timing analysis available for premium members.
I am quite unsure about when it is appropriate to use exceptions or not. Recently, I read an article mentioning that not everything should be handled with exceptions; they should only be used in cases where the system really needs to stop and report the issue. On the other hand, in scenarios such as consuming an API, this might not be the best approach. The code below is an integration with a ZIP code lookup API, allowing the user to enter a value and return the corresponding address. If the `error` property is equal to `true`, this indicates that the ZIP code may be incorrect or that the address does not exist: AddressResponse? address = await response.Content .ReadFromJsonAsync<AddressResponse>(token) .ConfigureAwait(false); return !response.IsSuccessStatusCode || address?.Error == "true" ? throw new HttpRequestException("Address not found.") : address; Next, the code that calls the method above iterates over a list using `Task.WhenAll`. In this case, the question arises: is it wrong to use `try/catch` and add errors into a `ConcurrentBag` (in this example, `errors.Add`), or would it be better to return a result object that indicates success or failure? AddressResponse?[] responses = await Task .WhenAll(zipCodes .Select(async zipCode => { try { return await service.GetAddressAsync(zipCode, token); } catch (Exception ex) { errors.Add($"Error: {ex.Message}"); return null; } })); This is a simple program for integrating with an API, but it serves as an example of how to improve a real-world application. *Note: the C# syntax is really beautiful.*
I’ve been testing the new \*\*ProblemDetails support in .NET 9\*\*, and I think it’s a great way to standardize error responses. Before, each API returned errors in a different format (plain text, HTML, custom JSON). With ProblemDetails, you always get a consistent JSON structure following \*\*RFC 7807\*\*: \`\`\`json { "type": "...", "title": "...", "status": 400, "detail": "...", "instance": "..." } I really like how easy it is to enable in .NET 9: builder.Services.AddProblemDetails(); app.UseExceptionHandler(); More info: [https://www.youtube.com/watch?v=ZBH0xBGuCfE&ab\_channel=SherlockCode](https://www.youtube.com/watch?v=ZBH0xBGuCfE&ab_channel=SherlockCode)
Hey everyone, I keep running into this problem while testing APIs during development: What tool shall I use to test APIs, we do have multiple options, but everyone comes with flaws as well, * Swagger is nice, but all my request payloads disappear when I refresh 😩. * Postman works, but my company didn't allow installing it on dev(jump) servers. * On my personal laptop, running VS + browser + Postman together just eats RAM and slows things down. So I thought: why not bring API testing *inside Visual Studio itself*? No switching, no extra apps. I’ve started building an extension (early MVP is live on the Marketplace, not fully stable yet). My goals: * Test APIs directly from VS (no external tools). * Save collection locally(no more lost Swagger payloads). * Reduce memory usage and context switching. * no login, no cloud sync 👉 I’d love your thoughts: * Would you use something like this? * What features would you want before considering it as a Postman alternative? * Any pain points I’m missing? If you’re curious, the MVP is here (feel free to try and share feedback/bugs): [Visual Studio Marketplace – SmartPing](https://marketplace.visualstudio.com/items?itemName=Mrdd.SmartPing) After installing please check tools section in visual studio's menus
I’ve seen a lot of patterns over the years: * Returning null * Throwing exceptions for non-exceptional cases * Custom status objects duplicated across services They all work, but they can get messy. I’ve been experimenting with a lightweight approach using a simple Result / Result<T> abstraction. For example: https://preview.redd.it/t0x9oebdocpf1.png?width=808&format=png&auto=webp&s=5176ef86862849faaafd114bb87aa272764d864e And then in the API layer: https://preview.redd.it/234bt5kiocpf1.png?width=1178&format=png&auto=webp&s=675e567ff74e7239fbb2a7b2ccbe360c9fc08e32 This pattern has kept my service layers clean and made APIs more consistent. Curious: how are you all handling this in your projects? (*Edit: I’ve put together a small OSS library called Knight.Response around this idea — details in comments if anyone’s interested.*)
I saw a post here, the consensus is largely to not throw exceptions - and instead return a result pattern. https://www.reddit.com/r/csharp/s/q4YGm3mVFm I understand the concept of a result pattern, but I am confused on how the result pattern works with a problem details middleware. If I return a resort pattern from my service layer, how does that play into problem details? Within my problem details middleware, I can handle different types of exceptions, and return different types of responses based on the type of exception. I'm not sure how this would work with the result pattern. Can anyone enlighten me please? Thank you
+6 more signals