<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: dotnet</title>
    <description>The latest articles tagged 'dotnet' on DEV Community.</description>
    <link>https://dev.to/t/dotnet</link>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tag/dotnet"/>
    <language>en</language>
    <item>
      <title>IAsyncEnumerable&lt;T&gt; Streaming</title>
      <dc:creator>Maayur Dahake</dc:creator>
      <pubDate>Tue, 17 Nov 2026 20:44:43 +0000</pubDate>
      <link>https://dev.to/maayurdahake/iasyncenumerable-streaming-m69</link>
      <guid>https://dev.to/maayurdahake/iasyncenumerable-streaming-m69</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnxrji03nkv231m9haego.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnxrji03nkv231m9haego.png" alt="IAsyncEnumerable&lt;T&gt; Streaming" width="800" height="1000"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Memory Trap of Materialization
&lt;/h3&gt;

&lt;p&gt;During a recent performance audit of our reporting APIs, I tracked down erratic Gen2 GC pauses to a seemingly innocent endpoint. The code called &lt;code&gt;.ToListAsync()&lt;/code&gt; on a massive table containing over 50,000 historical transaction records before returning an &lt;code&gt;Ok(list)&lt;/code&gt; response.&lt;/p&gt;

&lt;p&gt;This approach forces ASP.NET Core to allocate the entire result set in memory, doubling or tripling allocations during JSON serialization and locking up thread pool resources.&lt;/p&gt;

&lt;h3&gt;
  
  
  Before
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;HttpGet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"reports"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;IActionResult&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;GetReports&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToListAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// buffers all rows in RAM&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  After
&lt;/h3&gt;

&lt;p&gt;By leveraging &lt;code&gt;IAsyncEnumerable&amp;lt;T&amp;gt;&lt;/code&gt; straight from Entity Framework Core, we bypass the intermediate list allocation entirely. The ASP.NET Core framework understands this interface and immediately streams the records down the HTTP response pipe as data flows from the underlying SQL Server data reader.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;HttpGet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"reports"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;IAsyncEnumerable&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;GetReports&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AsAsyncEnumerable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why It Matters
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Heap Allocations:&lt;/strong&gt; Bypasses temporary &lt;code&gt;List&amp;lt;T&amp;gt;&lt;/code&gt; backing arrays, keeping memory usage flat regardless of row count.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time-to-First-Byte:&lt;/strong&gt; The client receives the first JSON chunk instantly instead of waiting for the full query to materialize on the server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Concurrency:&lt;/strong&gt; Frees up worker threads from waiting on massive memory allocations during peak traffic.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Watch Out
&lt;/h3&gt;

&lt;p&gt;If an exception occurs halfway through reading the stream, your &lt;code&gt;DbContext&lt;/code&gt; instance may already be disposed depending on how the request scope handles asynchronous disposal. Ensure your middleware handles mid-stream failures gracefully without corrupting HTTP headers.&lt;/p&gt;

&lt;p&gt;How do you handle large data exports in your current architecture?&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>performance</category>
      <category>programming</category>
    </item>
    <item>
      <title>The tests were green, a person found the hole: a vulnerability in our OpenID server, start to finish</title>
      <dc:creator>rinat kozin</dc:creator>
      <pubDate>Tue, 17 Nov 2026 20:18:09 +0000</pubDate>
      <link>https://dev.to/rinat_kozin/the-tests-were-green-a-person-found-the-hole-a-vulnerability-in-our-openid-server-start-to-finish-9fj</link>
      <guid>https://dev.to/rinat_kozin/the-tests-were-green-a-person-found-the-hole-a-vulnerability-in-our-openid-server-start-to-finish-9fj</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdq2tq3656o7mc7omol98.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdq2tq3656o7mc7omol98.png" alt="redb.Identity" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How many green tests does it take to believe a protection works? We have about two thousand, and they pass on three databases. A person still found the hole: an outside researcher who worked through our server and saw a connection where we had seen none.&lt;/p&gt;

&lt;p&gt;This is the story of &lt;a href="https://github.com/redbase-app/redb-identity/security/advisories/GHSA-vmj2-8phj-mfxf" rel="noopener noreferrer"&gt;GHSA-vmj2-8phj-mfxf&lt;/a&gt; in redb.Identity, our OAuth 2.1 / OpenID Connect server for .NET. In order and with dates: what was broken, why we did not see it ourselves, how we fixed it and how we disclosed it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The report
&lt;/h2&gt;

&lt;p&gt;On 4 November a private report on version 4.6.1 came in. Its author, Rathnadeepan (HotWater, &lt;a href="https://github.com/HotWater-015" rel="noopener noreferrer"&gt;HotWater-015&lt;/a&gt; on GitHub), did not open a public issue or write a blog post about it. He wrote to us directly and left us time to fix it.&lt;/p&gt;

&lt;p&gt;We checked the report against the source the same day. It was all true.&lt;/p&gt;

&lt;h2&gt;
  
  
  DPoP in two paragraphs
&lt;/h2&gt;

&lt;p&gt;A plain access token is accepted from anyone who presents it. If it is stolen from a log, a proxy or an intermediate node, it can be used. &lt;a href="https://www.rfc-editor.org/rfc/rfc9449" rel="noopener noreferrer"&gt;DPoP (RFC 9449)&lt;/a&gt; changes that by binding the token to the client's key. The token carries the key's thumbprint (&lt;code&gt;cnf.jkt&lt;/code&gt;), and with every request the client sends a short proof signed by that key: method, URL, time, a one-time identifier and the hash of the token itself. Without the private key there is no proof, so a stolen token is useless.&lt;/p&gt;

&lt;p&gt;We wrote about this in detail in &lt;a href="https://redbase.app/articles/identity-token-theft" rel="noopener noreferrer"&gt;Your access token was stolen. Now what&lt;/a&gt;. That made it all the more unpleasant to learn that at two endpoints of our own server this protection did not work.&lt;/p&gt;

&lt;h2&gt;
  
  
  What was broken
&lt;/h2&gt;

&lt;p&gt;With DPoP enabled (&lt;code&gt;Dpop.Enabled = true&lt;/code&gt;, off by default), the server issues tokens bound to a key. The proof of possession was checked only when the token was issued, at &lt;code&gt;/connect/token&lt;/code&gt;. Two endpoints of the server itself, &lt;code&gt;/connect/userinfo&lt;/code&gt; and the management API &lt;code&gt;/api/v1/identity/...&lt;/code&gt; (SCIM included), read only the Bearer scheme and never looked at the &lt;code&gt;DPoP&lt;/code&gt; header.&lt;/p&gt;

&lt;p&gt;So a bound token was accepted there as a plain Bearer token: with no proof and without the key it is bound to. Someone who had obtained such a token, but not the client's private key, could read the user's claims at userinfo and use the management API within the token's scope.&lt;/p&gt;

&lt;p&gt;Affected: redb.Identity.Core versions 1.0.1 through 4.6.1 (fixed in 4.6.2), and only deployments with DPoP enabled. Resource servers that validate tokens with &lt;code&gt;redb.Identity.Resource.Dpop&lt;/code&gt; were not affected: the proof was always checked there. CVSS 3.1 score 7.4, High, class CWE-287 (improper authentication).&lt;/p&gt;

&lt;h2&gt;
  
  
  Why we did not see it
&lt;/h2&gt;

&lt;p&gt;Ever since DPoP arrived in the 1.x line, userinfo and the management API read only the Bearer scheme. Nobody looked at the &lt;code&gt;cnf&lt;/code&gt; field at these endpoints, and a bound token went through like any other.&lt;/p&gt;

&lt;p&gt;In October we moved to OpenIddict 7. Unlike version 6, it checks &lt;code&gt;cnf&lt;/code&gt; on every token, but it only understands certificate binding (&lt;code&gt;x5t#S256&lt;/code&gt;). On a token bound to a DPoP key it threw an exception, and in the 4.4.0 prereleases userinfo and the management API answered 500. That was the only period when a bound token did not get through at these endpoints, and the cause was an exception, not a check. We fixed the error: in front of the OpenIddict check we put a handler that turns it off for tokens with &lt;code&gt;jkt&lt;/code&gt;. The change description says it plainly: the DPoP proof is checked by Identity itself.&lt;/p&gt;

&lt;p&gt;That assumption was wrong: at these two endpoints nobody checked the proof, and from the 4.4.0 release on a bound token was accepted as Bearer again.&lt;/p&gt;

&lt;p&gt;Along with that fix came a test, "userinfo accepts a DPoP-bound token". It obtained a token, called userinfo with the Bearer scheme and a &lt;code&gt;DPoP&lt;/code&gt; header, and expected 200. The answer was 200, the test was green. But the server never read that header, and without it the answer would have been the same. The test checked that a good request goes through, and in doing so it locked in the very defect that a person from outside found later.&lt;/p&gt;

&lt;p&gt;The conclusion we drew: for a protection mechanism, a "must accept" test without a "must refuse" test proves almost nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The first day and night
&lt;/h2&gt;

&lt;p&gt;We confirmed the defect by reading the source the same day. We also checked how far back it went: the new tests were run on a commit that still used OpenIddict 6.3, and the token was accepted there too. Hence the range in the advisory, from 1.0.1.&lt;/p&gt;

&lt;p&gt;Then, in order:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;23:06, 4 November.&lt;/strong&gt; A failing test first: 18 cases on userinfo and the management API. A bound token as Bearer without a proof, as Bearer with a proof, a proof from another key, a replayed proof, a proof for another URL or method, an expired one, one without &lt;code&gt;ath&lt;/code&gt;; an unbound token under the DPoP scheme; and next to them a check that a plain unbound Bearer token is still accepted.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;23:33.&lt;/strong&gt; The fix; the new tests green.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The night of 5 November.&lt;/strong&gt; Full runs on PostgreSQL, SQL Server and SQLite: 2007 tests on each database, none failed. Then the upgrade notes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;5 November.&lt;/strong&gt; Release 4.6.2.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now a bound token is accepted at these endpoints only under the &lt;code&gt;DPoP&lt;/code&gt; scheme with a valid proof: signed by the bound key, matching method and URL, &lt;code&gt;ath&lt;/code&gt; equal to the token hash, a fresh time, an unused &lt;code&gt;jti&lt;/code&gt;. Otherwise the answer is 401 with the challenge &lt;code&gt;WWW-Authenticate: DPoP error="invalid_token"&lt;/code&gt;. Plain unbound Bearer tokens and certificate-bound tokens work as before.&lt;/p&gt;

&lt;p&gt;Our management API is also available over gRPC and SOAP. There is nowhere to carry a DPoP proof there, so a bound token is now refused on these channels: gRPC answers &lt;code&gt;Unauthenticated&lt;/code&gt;, SOAP returns a fault. They need a plain Bearer token, or the HTTP API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Disclosure
&lt;/h2&gt;

&lt;p&gt;The advisory stayed private until the reporter agreed to publication. We asked GitHub for a CVE number twice, on 5 and 11 November, and no number came. We did not wait longer: with the reporter's consent the advisory was published on 15 November under its GHSA identifier. If a CVE is assigned later, we will add it.&lt;/p&gt;

&lt;p&gt;Why the number is taking so long, we were not told. Our guess: vulnerabilities are being searched for very actively right now, breaches of large companies are reported all the time, and findings in small and open source projects are more numerous still. There seem to be so many CVE requests that GitHub cannot keep up. For a small project the conclusion is simple: publish the advisory yourself once the fix is out and the reporter agrees, and add the number when it arrives.&lt;/p&gt;

&lt;p&gt;By the time everyone learned about the hole, the fix had been on NuGet for ten days. That was possible because the reporter sent the finding to us, not to a public tracker, and gave us time to close it.&lt;/p&gt;

&lt;p&gt;Our side is to answer fast, fix fast, credit the reporter by name and publish the advisory even without a CVE number.&lt;/p&gt;

&lt;h2&gt;
  
  
  Holes like this are found by people
&lt;/h2&gt;

&lt;p&gt;Tests, release checks and our own review check what we imagined ourselves. If the developer's picture is "the proof is checked somewhere else", the test gets written for that picture and passes. Two thousand green tests say nothing about what is missing from the picture.&lt;/p&gt;

&lt;p&gt;This vulnerability did not sit in one line. It was assembled from several things that each looked harmless and had no obvious link to one another:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;endpoints that had read only the Bearer scheme since the first versions;&lt;/li&gt;
&lt;li&gt;a library check we switched off to get rid of a 500 error;&lt;/li&gt;
&lt;li&gt;the description of that change, saying the proof is checked elsewhere;&lt;/li&gt;
&lt;li&gt;a test that confirmed a good request goes through.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Someone had looked at each of these, and each one on its own was fine. They live in different places in the code and appeared in different months. To see the hole you have to hold all of them in your head at once and ask where the key is actually checked. Automated checks do not ask that question; they look at each part separately. Vulnerabilities like this are found by a person who studies the system and reasons about it.&lt;/p&gt;

&lt;p&gt;So a report from an outsider is, for us, a review he did on our behalf. Reports like this are very valuable to us, and I think to other projects too. Rathnadeepan, thank you.&lt;/p&gt;

&lt;p&gt;What do you think?&lt;/p&gt;

&lt;h2&gt;
  
  
  What we changed
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Refusal tests for every protected endpoint.&lt;/strong&gt; A separate test for each form of bad request, checking that the server refuses it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Demos on every built image.&lt;/strong&gt; Our own DPoP demo still called userinfo the old way after 4.6.2, with the Bearer scheme, and expected 200. We only noticed on 14 November, when we first ran the whole demo set against a full image built from the main branch: that step answered 401, as it should after the fix. The demo now follows RFC 9449, section 7.1: userinfo with the DPoP scheme, and the Bearer form must be refused. The demo set now runs on every full image build and in the checks before a release.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An advisory even without a CVE.&lt;/strong&gt; Users learn about a hole from our changelog and advisory, and do not wait for a number.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  If you use redb.Identity with DPoP
&lt;/h2&gt;

&lt;p&gt;Update &lt;code&gt;redb.Identity.Core&lt;/code&gt; to 4.6.2 or later: the fix lives there. Update &lt;code&gt;redb.Identity.Http&lt;/code&gt; along with it, so that userinfo answers the client with the DPoP challenge; with an older &lt;code&gt;redb.Identity.Http&lt;/code&gt; a token without a proof still gets 401, only the challenge comes in the Bearer form. Clients that obtain bound tokens and call userinfo or the management API need to send the &lt;code&gt;DPoP&lt;/code&gt; scheme and a proof with &lt;code&gt;ath&lt;/code&gt;; details in &lt;a href="https://github.com/redbase-app/redb-identity/blob/main/UPGRADING.md" rel="noopener noreferrer"&gt;UPGRADING.md&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you cannot update right away, there is no setting that restores the check. Shorten the access token lifetime and revoke tokens that may have leaked. If DPoP is off in your deployment, the defect does not affect you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Over to you
&lt;/h2&gt;

&lt;p&gt;How does this work in your projects? Is there a clear channel for security reports, and what happens when a report arrives: who reads it, how long does it wait for an answer? Have you waited weeks for a CVE number, and how did it end? And if you have found holes in someone else's code, how were you received? Tell us in the comments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;If this was useful, a ⭐ on &lt;a href="https://github.com/redbase-app" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; helps others find it.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;More of my writing: &lt;a href="https://redbase.app/articles" rel="noopener noreferrer"&gt;redbase.app/articles&lt;/a&gt;, and on &lt;a href="https://dev.to/rinat_kozin"&gt;dev.to&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>security</category>
      <category>oauth</category>
      <category>dpop</category>
    </item>
    <item>
      <title>The problem was real before the architecture became complicated</title>
      <dc:creator>Odecio Souza</dc:creator>
      <pubDate>Tue, 17 Nov 2026 18:16:28 +0000</pubDate>
      <link>https://dev.to/odecius/the-problem-was-real-before-the-architecture-became-complicated-3ibm</link>
      <guid>https://dev.to/odecius/the-problem-was-real-before-the-architecture-became-complicated-3ibm</guid>
      <description>&lt;p&gt;Odecio Souza · Software Developer | Backend Systems, APIs &amp;amp; Automation · ABC Solutions&lt;/p&gt;

&lt;p&gt;Build. Secure. Automate. Share.&lt;/p&gt;

&lt;p&gt;The problem was real before the architecture became complicated&lt;br&gt;
I started Agenda de Contas to organise household bills, track payments and plan recurring financial commitments. My household and I use it regularly, and it meets our main organisational needs. The application organises financial obligations; it does not process payments or provide regulated financial services.&lt;/p&gt;

&lt;p&gt;The first version was an ASP.NET Core application with a browser interface and JSON-based persistence. Alongside the account and payment workflows, I developed reminders and a routine for operating the application on my own Linux infrastructure.&lt;/p&gt;

&lt;p&gt;Later, I wanted to support individual logins and multiple families, each with its own accounts, payments, settings and permissions. That raised a more difficult question:&lt;/p&gt;

&lt;p&gt;How could I add a multi-family architecture without putting an application I already relied on at unnecessary risk?&lt;/p&gt;

&lt;p&gt;Keep a working baseline working&lt;br&gt;
The most tempting migration plan was to replace JSON with PostgreSQL and move on. I resisted that all-at-once approach because the existing application was not a disposable prototype. It was being used in real life.&lt;/p&gt;

&lt;p&gt;I chose to evolve the system incrementally. The documented baseline retained the original JSON store while PostgreSQL, EF Core and individual identity support were developed separately. A feature boundary kept the new multi-family path from automatically replacing the working one.&lt;/p&gt;

&lt;p&gt;The distinction matters: code can be implemented, reviewed and merged without becoming the documented production baseline.&lt;/p&gt;

&lt;p&gt;Here is a simplified view of the two execution paths described in the architecture documentation:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 ASP.NET Core application
                            |
                     Multi-family gate
                       /          \
                      /            \
              Disabled              Enabled
          (documented baseline)    (controlled testing)
                  |                  |
             ContaStore          Identity + family context
                  |                  |
                JSON             Scoped repositories
                                     |
                                 PostgreSQL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The diagram omits private hosting details. It represents the documented production baseline on the left and a controlled development and test path on the right; it does not prove a PostgreSQL production cutover.&lt;/p&gt;

&lt;p&gt;One database per family or a shared database?&lt;br&gt;
One design decision involved a genuine discussion about how to isolate families.&lt;/p&gt;

&lt;p&gt;I considered two approaches:&lt;/p&gt;

&lt;p&gt;Give each family its own database.&lt;br&gt;
Use a shared PostgreSQL database with strict logical isolation between families.&lt;br&gt;
A separate database for every family can provide physical separation. But for my requirements, it would also increase the work involved in provisioning, schema migrations, maintenance and backups. I considered that complexity disproportionate for the stage of the project.&lt;/p&gt;

&lt;p&gt;I therefore chose a shared-database design with family-scoped access.&lt;/p&gt;

&lt;p&gt;The selected design avoids managing a database for every family, but it makes application and data isolation essential. Those boundaries were implemented and tested as part of the new architecture, not activated as a verified production cutover.&lt;/p&gt;

&lt;p&gt;Tenant isolation needs more than FamilyId&lt;br&gt;
I designed for defence in depth: membership rules, a selected-family context, repository-level scoping, relational constraints and tests that attempt to cross family boundaries.&lt;/p&gt;

&lt;p&gt;The multi-family model contains users, families and memberships. A user's Owner, Admin or Member role belongs to their membership in a particular family, not to their identity globally. Accounts, payments, reminders and settings are family-owned. Scoped repositories and authorisation protect read access, while relational constraints help prevent invalid cross-family relationships.&lt;/p&gt;

&lt;p&gt;Make the migration explicit and repeatable&lt;br&gt;
Another challenge was the transition of existing records.&lt;/p&gt;

&lt;p&gt;I wanted a controlled process rather than an automatic migration silently triggered on application startup. The developed importer was designed around a few principles:&lt;/p&gt;

&lt;p&gt;Explicit execution: importing data is a deliberate operation, not a hidden side effect.&lt;br&gt;
Dry-run support: the operator can inspect an intended import without writing records.&lt;br&gt;
Deterministic mapping: the same source records should map consistently.&lt;br&gt;
Idempotency: repeating a successful operation should not create duplicates.&lt;br&gt;
Transactions: a failed operation should not leave partially migrated data.&lt;br&gt;
Strict input validation: missing required JSON collections should not be mistaken for deliberately empty ones.&lt;br&gt;
A concrete validation case illustrates the risk: a JSON object containing only {} should not be accepted as a successful empty import when the required collections are absent. An intentionally empty array is different from a missing or null collection. The documented importer tests this distinction rather than treating incomplete input as a reassuring zero-record result.&lt;/p&gt;

&lt;p&gt;I learned to value clear failure behaviour more than a superficially smooth migration.&lt;/p&gt;

&lt;p&gt;Test what must not happen&lt;br&gt;
Supporting multiple families changes the security model.&lt;/p&gt;

&lt;p&gt;It is not enough for one user to see their own records when everything is configured correctly. I also need evidence that the application rejects access to records belonging to another family.&lt;/p&gt;

&lt;p&gt;The documented tests check tenant isolation, invalid roles and memberships, duplicate constraints and cross-family account/payment relationships.&lt;/p&gt;

&lt;p&gt;For example, consider an attempt to associate a Family A payment with a Family B account. Repository scoping should prevent cross-family reads, and relational constraints should reject an invalid relationship. This illustrates a tested boundary using fictional families; it is not a real data-exposure incident.&lt;/p&gt;

&lt;p&gt;Individual authentication introduced further concerns. Invitation and password-recovery flows need careful token handling and must avoid unnecessarily revealing whether an account exists. Delivery was separated from token generation so that the flows could be tested without relying on a real notification provider or embedding credentials in source code.&lt;/p&gt;

&lt;p&gt;For relational tests, the project used disposable PostgreSQL environments. That made it possible to validate database behaviour without touching the data in my household's existing application.&lt;/p&gt;

&lt;p&gt;Operations require separate evidence&lt;br&gt;
Developing software and operating it are different kinds of responsibility.&lt;/p&gt;

&lt;p&gt;I researched and configured Linux and Docker infrastructure, deployment routines, secure access and automated backups. This work was challenging. It involved documentation, experiments, repeated troubleshooting and learning how to verify that an operation had genuinely succeeded.&lt;/p&gt;

&lt;p&gt;Backup hardening is a good example. The reviewed implementation added integrity checks before marking transfers complete, stronger handling of unexpected paths, and compatibility checks for legacy manifest formats.&lt;/p&gt;

&lt;p&gt;However, a passing synthetic test is not proof of deployment or recovery on a real machine. Restores and operational activation require separate evidence.&lt;/p&gt;

&lt;p&gt;What I would compare differently in retrospect&lt;br&gt;
The separate-database versus shared-database discussion was a real architectural choice during development. Other possibilities are useful retrospective comparisons, not decisions I claim to have explicitly considered at that time.&lt;/p&gt;

&lt;p&gt;For example, replacing JSON immediately might have shortened the transition on paper, but it would have combined data conversion with identity and tenancy changes. Relying exclusively on application query filters would reduce some schema work, but it would provide less protection against invalid relationships or missed filters. Treating roles as global would simplify early code but misrepresent permissions for users belonging to several families.&lt;/p&gt;

&lt;p&gt;Reflecting on those alternatives has helped me explain why I prefer staged change, explicit tenant boundaries and independent validation.&lt;/p&gt;

&lt;p&gt;What runs today and what comes next&lt;br&gt;
As of 17 November 2026, repository documentation identifies JSON persistence as the documented production baseline. PostgreSQL multi-family features have been developed and tested; a live cutover has not been verified.&lt;/p&gt;

&lt;p&gt;My household's ongoing use is real, but I am not claiming external customer adoption, commercial revenue or measured time savings. An external-user pilot remains a future milestone.&lt;/p&gt;

&lt;p&gt;Before that pilot, I want controlled deployment evidence, an isolated database, checked backup and recovery procedures, a rehearsed import and a rollback plan.&lt;/p&gt;

&lt;p&gt;I have learned that engineering means researching alternatives, protecting what works and separating technical progress from operational proof.&lt;/p&gt;

&lt;p&gt;The safest migration was not the one that replaced JSON fastest. It was the one that made each consequential step explicit, testable and reversible wherever possible.&lt;/p&gt;

&lt;p&gt;Public engineering references&lt;br&gt;
The development history can be explored through public GitHub pull requests:&lt;/p&gt;

&lt;p&gt;Agenda de Contas project&lt;br&gt;
Identity and tenant isolation — PR #2&lt;br&gt;
Controlled JSON import — PR #4&lt;br&gt;
Family management — PR #10&lt;br&gt;
Off-host backup hardening — PR #14&lt;br&gt;
Transport manifest compatibility — PR #15&lt;br&gt;
Verification manifest compatibility — PR #16&lt;br&gt;
These references support the implementation history. They do not independently verify my household's experience or current server state.&lt;/p&gt;

&lt;p&gt;About the author and AI assistance&lt;br&gt;
I conceived and directed the project, researched technical choices, evaluated alternatives, supervised development, carried out operational work and reviewed and validated results. ChatGPT and Codex assisted materially with research, implementation, troubleshooting, tests and technical documentation. I remain responsible for the direction of the project and the accuracy of this account; I do not claim that all code was written manually without assistance.&lt;/p&gt;

&lt;p&gt;Odecio Souza&lt;br&gt;
Software Developer | Backend Systems, APIs &amp;amp; Automation&lt;br&gt;
ABC Solutions · Build. Secure. Automate. Share.&lt;/p&gt;

&lt;p&gt;GitHub · LinkedIn · ABC Solutions&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>automation</category>
      <category>backend</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>Parsing HTML in .NET 10–30x faster than HtmlAgilityPack and AngleSharp: a list of tags instead of a DOM</title>
      <dc:creator>RomanT</dc:creator>
      <pubDate>Tue, 17 Nov 2026 14:46:26 +0000</pubDate>
      <link>https://dev.to/romanti3172/parsing-html-in-net-10-30x-faster-than-htmlagilitypack-and-anglesharp-a-list-of-tags-instead-of-a-2cab</link>
      <guid>https://dev.to/romanti3172/parsing-html-in-net-10-30x-faster-than-htmlagilitypack-and-anglesharp-a-list-of-tags-instead-of-a-2cab</guid>
      <description>&lt;p&gt;I have been scraping catalogs, prices, product cards and listings for years. All that time a small homegrown HTML parser did the work: millions of pages, no complaints. It never went public because its tests covered only my own sites and there were no docs.&lt;/p&gt;

&lt;p&gt;Last week I cleaned it up and released it as &lt;strong&gt;&lt;a href="https://www.nuget.org/packages/z3l.FastHtmlParser" rel="noopener noreferrer"&gt;z3l.FastHtmlParser&lt;/a&gt;&lt;/strong&gt;. The first version answered "how do I find a tag fast". Since then it has gone through five releases in one week, driven by feedback: XPath 1.0, CSS selectors, a review against hostile markup, and parsing straight from a &lt;code&gt;char[]&lt;/code&gt; buffer. This post covers the idea, the numbers and the trade-offs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet add package z3l.FastHtmlParser
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  A DOM is more than a scraper needs
&lt;/h2&gt;

&lt;p&gt;In a high-volume scraping service the parser is the hottest loop, and your server bill grows with it.&lt;/p&gt;

&lt;p&gt;HtmlAgilityPack and AngleSharp are excellent libraries, but they are built to be browsers. They create an object for every node, synthesize the implicit &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;tbody&amp;gt;&lt;/code&gt;, and keep a mutable tree so you can edit it and walk it with selectors.&lt;/p&gt;

&lt;p&gt;A scraper does far less: find an element, read its text or an attribute, move on. So the idea is simple: &lt;strong&gt;don't build what you won't use.&lt;/strong&gt; The document is the source string plus a flat list of tags, each one a set of integer offsets into that string.&lt;/p&gt;

&lt;h2&gt;
  
  
  The numbers
&lt;/h2&gt;

&lt;p&gt;BenchmarkDotNet 0.15.8, .NET 10, Intel Xeon E-2236, Windows Server 2025. Pages are real saved pages of books.toscrape.com, quotes.toscrape.com and webscraper.io test sites. AngleSharp 1.10.0, HtmlAgilityPack 1.13.1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parse a page, time&lt;/strong&gt; (lower is better):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Page&lt;/th&gt;
&lt;th&gt;FastHtmlParser&lt;/th&gt;
&lt;th&gt;HtmlAgilityPack&lt;/th&gt;
&lt;th&gt;AngleSharp&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;quotes, 11 KB&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;17 μs&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;155 μs&lt;/td&gt;
&lt;td&gt;229 μs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;laptops, 38 KB&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;53 μs&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;544 μs&lt;/td&gt;
&lt;td&gt;959 μs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;books, 51 KB&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;59 μs&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;610 μs&lt;/td&gt;
&lt;td&gt;958 μs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;books, no end tags*&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;59 μs&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;671 μs&lt;/td&gt;
&lt;td&gt;949 μs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;books ×10, 510 KB&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0.61 ms&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;19.6 ms&lt;/td&gt;
&lt;td&gt;12.2 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Parse a page, memory allocated:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Page&lt;/th&gt;
&lt;th&gt;FastHtmlParser&lt;/th&gt;
&lt;th&gt;HtmlAgilityPack&lt;/th&gt;
&lt;th&gt;AngleSharp&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;quotes, 11 KB&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;11 KB&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;243 KB&lt;/td&gt;
&lt;td&gt;189 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;laptops, 38 KB&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;31 KB&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;713 KB&lt;/td&gt;
&lt;td&gt;608 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;books, 51 KB&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;39 KB&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;812 KB&lt;/td&gt;
&lt;td&gt;663 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;books, no end tags*&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;39 KB&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;756 KB&lt;/td&gt;
&lt;td&gt;644 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;books ×10, 510 KB&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;391 KB&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;8.1 MB&lt;/td&gt;
&lt;td&gt;6.3 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;* The books page with all 75 &lt;code&gt;&amp;lt;/li&amp;gt;&lt;/code&gt; and 60 &lt;code&gt;&amp;lt;/p&amp;gt;&lt;/code&gt; removed, as on sloppy sites.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parse and extract 20 books&lt;/strong&gt; (title, price, rating). All libraries return exactly the same records; the setup checks it.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Library&lt;/th&gt;
&lt;th&gt;Time&lt;/th&gt;
&lt;th&gt;Allocated&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;z3l.FastHtmlParser&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;69 μs&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;45 KB&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;… with CSS selectors&lt;/td&gt;
&lt;td&gt;75 μs&lt;/td&gt;
&lt;td&gt;45 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;… with XPath&lt;/td&gt;
&lt;td&gt;109 μs&lt;/td&gt;
&lt;td&gt;173 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HtmlAgilityPack (XPath)&lt;/td&gt;
&lt;td&gt;760 μs&lt;/td&gt;
&lt;td&gt;1,038 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AngleSharp (CSS selectors)&lt;/td&gt;
&lt;td&gt;1,043 μs&lt;/td&gt;
&lt;td&gt;707 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The interesting row is the CSS one: &lt;strong&gt;the same selectors AngleSharp runs are about 14x faster here, with 16x less memory.&lt;/strong&gt; You don't have to learn a new API to get most of the speed.&lt;/p&gt;

&lt;p&gt;On a real 1 MB Amazon search results page (100+ inline scripts, ~4,000 tags) parsing takes 0.65 ms against 11.3 ms (HtmlAgilityPack) and 15.1 ms (AngleSharp), and extracting 27 products takes 0.87 ms against 16.3 ms and 18.1 ms, with 23–29x less memory. That page isn't in the repo for copyright reasons; save your own as &lt;code&gt;benchmarks/local/amazon*.html&lt;/code&gt; and run &lt;code&gt;LocalScrapeBenchmarks&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the API looks like
&lt;/h2&gt;

&lt;p&gt;Three ways to query, pick whichever you like. All of them work on the document or inside a tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="n"&gt;z3l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FastHtmlParser&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HtmlParser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;html&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"https://books.toscrape.com/"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// 1. Find / FindAll: enums for tag and attribute names, no allocations while matching&lt;/span&gt;
&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FindAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TagQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HtmlTag&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Article&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Class&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"product_pod"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HtmlTag&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;H3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HtmlTag&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;A&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AttributeByName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HtmlAttribute&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Title&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HtmlTag&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;P&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"price_color"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;link&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HtmlTag&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;A&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AttributeHref&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// absolute URL, resolved against the page&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// 2. CSS selectors, as querySelectorAll / querySelector in a browser&lt;/span&gt;
&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Css&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"article.product_pod h3 &amp;gt; a"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Css&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"div.quote:has(a.tag[href*=love]) span.text"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CssFirst&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ul#menu &amp;gt; li:last-child a"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AttributeHref&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// 3. XPath 1.0&lt;/span&gt;
&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;XPathValues&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"//a[contains(@href, '/product/')]/@href"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;XPathValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"//dt[.='Price']/following-sibling::dd[1]"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// compile once, reuse on any number of pages and threads&lt;/span&gt;
&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nc"&gt;CssQuery&lt;/span&gt; &lt;span class="nc"&gt;Prices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;CssQuery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"div.card span.price"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Css&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Prices&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Chains are null-safe: every method accepts &lt;code&gt;null&lt;/code&gt; and returns &lt;code&gt;null&lt;/code&gt;, so a missing element never throws in the middle of a chain.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;phone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HtmlTag&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Div&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"contacts"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HtmlTag&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"phone"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AttributeHrefTelephone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// null if any step is missing&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. A tag list instead of a tree
&lt;/h3&gt;

&lt;p&gt;Each tag stores only integers: where it starts and ends, where its inner content starts and ends, its depth and its parent. Text, inner HTML and attributes are computed on demand as slices of the source. Descendants of a tag are simply the tags that follow it in the list until one starts past its end, so "search inside a tag" is a plain indexed &lt;code&gt;for&lt;/code&gt; loop over a range.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Memory allocated once, at the exact size
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;'&amp;lt;'&lt;/code&gt; can't appear fewer times than there are tags, so a vectorized &lt;code&gt;Count('&amp;lt;')&lt;/code&gt; gives an upper bound. Working arrays are rented from &lt;code&gt;ArrayPool&amp;lt;T&amp;gt;.Shared&lt;/code&gt;, the final list is created once with &lt;code&gt;CollectionsMarshal.SetCount&lt;/code&gt;, and the rented arrays are cleared before they go back to the pool, so they don't keep the page alive. No &lt;code&gt;List&amp;lt;T&amp;gt;&lt;/code&gt; doubling, no copies.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Vectorized scanning
&lt;/h3&gt;

&lt;p&gt;Outside a tag only &lt;code&gt;'&amp;lt;'&lt;/code&gt; matters, found with vectorized &lt;code&gt;IndexOf&lt;/code&gt;. Inside a tag only &lt;code&gt;'&amp;lt;'&lt;/code&gt;, &lt;code&gt;'='&lt;/code&gt; and &lt;code&gt;'&amp;gt;'&lt;/code&gt; matter, found with &lt;code&gt;IndexOfAny&lt;/code&gt;. Quoted attribute values are skipped as a block, so &lt;code&gt;data-x="&amp;lt;p&amp;gt;...&amp;lt;/p&amp;gt;"&lt;/code&gt; doesn't break anything. &lt;code&gt;script&lt;/code&gt;, &lt;code&gt;style&lt;/code&gt;, &lt;code&gt;textarea&lt;/code&gt;, &lt;code&gt;title&lt;/code&gt; and the other raw-text elements are scanned straight to their end tag, as HTML5 says.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Tag names without strings
&lt;/h3&gt;

&lt;p&gt;Names are &lt;code&gt;ReadOnlySpan&amp;lt;char&amp;gt;&lt;/code&gt; looked up through &lt;code&gt;Dictionary&amp;lt;string, HtmlTag&amp;gt;.AlternateLookup&amp;lt;ReadOnlySpan&amp;lt;char&amp;gt;&amp;gt;&lt;/code&gt; (new in .NET 9) and turned into an enum. I tried &lt;code&gt;FrozenDictionary&lt;/code&gt; and dropped it: about 16 ms of JIT warm-up on first use against ~2 ms for a plain &lt;code&gt;Dictionary&lt;/code&gt;, and slower lookups on this workload. A custom comparer hashes the length plus three case-folded characters. The same trick drives the table of all 2,125 HTML5 named entities.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Queries without IEnumerable
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Find&lt;/code&gt;, &lt;code&gt;Parent&lt;/code&gt;, &lt;code&gt;Next&lt;/code&gt; and &lt;code&gt;NextSibling&lt;/code&gt; return a single tag through an indexed loop; &lt;code&gt;TagQuery&lt;/code&gt; is a struct passed by &lt;code&gt;in&lt;/code&gt;. A chain like &lt;code&gt;doc.Find(...).Find(...).NextSibling(...)&lt;/code&gt; allocates nothing on the heap; the only allocation is the final &lt;code&gt;Text()&lt;/code&gt; string.&lt;/p&gt;

&lt;h2&gt;
  
  
  Broken HTML
&lt;/h2&gt;

&lt;p&gt;Clean test pages are easy. Real pages leave out &lt;code&gt;&amp;lt;/li&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;/p&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;/td&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;/option&amp;gt;&lt;/code&gt;, and a naive parser then nests every &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; inside the previous one.&lt;/p&gt;

&lt;p&gt;I tried three fixes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Full HTML5 implicit-close rules in the main loop.&lt;/strong&gt; Correct, but 4–9% slower.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fast pass, then a local re-parse on trouble.&lt;/strong&gt; Fell apart on the books page without end tags: all 20 books sit in one &lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt;, so most of the page was rescanned. 61 μs became 119 μs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check the top of the open-tag stack when a tag opens.&lt;/strong&gt; If a new &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; opens while an unclosed &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; is on top, they're siblings: close the previous one. One integer comparison. This is the one that shipped.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The result is in the table above: the books page with all 75 &lt;code&gt;&amp;lt;/li&amp;gt;&lt;/code&gt; and 60 &lt;code&gt;&amp;lt;/p&amp;gt;&lt;/code&gt; removed parses in the same 59 μs as the original.&lt;/p&gt;

&lt;p&gt;Then came a review against hostile and random markup (version 1.3.0), and it found real bugs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;a title="see id=5" id="real"&amp;gt;&lt;/code&gt; reported the id as &lt;code&gt;5&lt;/code&gt;: attribute lookup now never looks inside another attribute's quoted value.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;br/&amp;gt;&lt;/code&gt; without a space was named &lt;code&gt;br/&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Thousands of unclosed tags followed by stray end tags took &lt;strong&gt;seconds&lt;/strong&gt;. Parsing is now linear on any markup.&lt;/li&gt;
&lt;li&gt;In 1.4.1, XPath like &lt;code&gt;//div//span//a&lt;/code&gt; on deeply nested or unclosed markup was quadratic: 20,000 nested tags took 16 s and gigabytes of memory. Now 3 ms.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The test suite runs every saved page and a set of broken-markup snippets through AngleSharp too, and checks that both find the same elements, texts, attribute values and parents, CSS selector results included. The only differences are the trees a browser builds implicitly, like an inserted &lt;code&gt;&amp;lt;tbody&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Parsing from a buffer
&lt;/h2&gt;

&lt;p&gt;If your HTTP client already reads into a pooled &lt;code&gt;char[]&lt;/code&gt;, you don't have to make a string out of it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MemoryPool&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Shared&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;maxChars&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Memory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Span&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;HtmlParser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// Dispose returns the buffer to the pool&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  When to use something else
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;You need to modify the document.&lt;/strong&gt; It's read-only (which is also why it's safe to query from many threads).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You need the browser's implicit tree.&lt;/strong&gt; No synthesized &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;tbody&amp;gt;&lt;/code&gt;; &lt;code&gt;table &amp;gt; tr&lt;/code&gt; matches as written in the source.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You're on .NET 8 or older.&lt;/strong&gt; The design depends on &lt;code&gt;AlternateLookup&lt;/code&gt;, so it targets .NET 9 and .NET 10 only.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You need JavaScript-rendered content.&lt;/strong&gt; It's a parser, not a browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A week ago CSS selectors and XPath were on this list. They aren't anymore.&lt;/p&gt;

&lt;h2&gt;
  
  
  License
&lt;/h2&gt;

&lt;p&gt;Free for individuals and for companies with under $1M annual revenue and fewer than 100 employees, commercial use included. Larger companies pay once: $1,000 per organization, perpetual, all versions, and it covers every z3l library. The source is on GitHub.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: &lt;a href="https://github.com/romanti3172/z3l.FastHtmlParser" rel="noopener noreferrer"&gt;https://github.com/romanti3172/z3l.FastHtmlParser&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;NuGet: &lt;a href="https://www.nuget.org/packages/z3l.FastHtmlParser" rel="noopener noreferrer"&gt;https://www.nuget.org/packages/z3l.FastHtmlParser&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Docs: &lt;a href="https://romanti3172.github.io/z3l.FastHtmlParser/" rel="noopener noreferrer"&gt;https://romanti3172.github.io/z3l.FastHtmlParser/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Benchmarks and how to run them: &lt;a href="https://github.com/romanti3172/z3l.FastHtmlParser/blob/main/benchmarks/README.md" rel="noopener noreferrer"&gt;benchmarks/README.md&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'd like to hear where it breaks: send a page it parses differently from your browser, and I'll add it to the tests.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>webscraping</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Build vs buy for embedded reporting in a SaaS product: an honest engineering cost model</title>
      <dc:creator>Razi Syed</dc:creator>
      <pubDate>Tue, 17 Nov 2026 14:15:09 +0000</pubDate>
      <link>https://dev.to/razisyed/build-vs-buy-for-embedded-reporting-in-a-saas-product-an-honest-engineering-cost-model-1nil</link>
      <guid>https://dev.to/razisyed/build-vs-buy-for-embedded-reporting-in-a-saas-product-an-honest-engineering-cost-model-1nil</guid>
      <description>&lt;p&gt;&lt;em&gt;By Razi Syed. Sample code: &lt;a href="https://github.com/dotnetreport/dotnetreport-aspnetcore-quickstart" rel="noopener noreferrer"&gt;github.com/dotnetreport/dotnetreport-aspnetcore-quickstart&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Sooner or later every SaaS product gets the same ticket: "customers want to build their own reports." Someone on the team says "we could just build that," someone else says "there are products for that," and the discussion turns into opinions about vendor lock-in versus not-invented-here.&lt;/p&gt;

&lt;p&gt;I'd rather settle it with arithmetic. I build &lt;a href="https://dotnetreport.com" rel="noopener noreferrer"&gt;Dotnet Report&lt;/a&gt; (disclosure: I work on it, so weigh my view accordingly), and I've watched plenty of teams make this call both ways. Building is sometimes the right answer. This article lays out a cost model you can fill in with your own numbers, the parts of the build that tend to be underestimated, and the questions that should push you one way or the other.&lt;/p&gt;

&lt;h2&gt;
  
  
  Version one is genuinely small
&lt;/h2&gt;

&lt;p&gt;Let's be fair to the build option. The first version of "custom reports" really can be an afternoon: a whitelist of fields, a few filters, a parameterised query, a table on screen.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// A deliberately minimal "report builder" endpoint.&lt;/span&gt;
&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nc"&gt;Dictionary&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;AllowedColumns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"customer"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"c.Name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"orderDate"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"o.OrderDate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"total"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"o.Total"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;MapPost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/reports/run"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ReportRequest&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ClaimsPrincipal&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;IDbConnection&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;cols&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Columns&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;AllowedColumns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ContainsKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; $&lt;span class="s2"&gt;"{AllowedColumns[c]} AS [{c}]"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sql&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; $@&lt;span class="s2"&gt;"SELECT {string.Join("&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;", cols)}
                 FROM Orders o JOIN Customers c ON c.Id = o.CustomerId
                 WHERE o.TenantId = @tenantId
                   AND o.OrderDate BETWEEN @from AND @to"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;QueryAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;tenantId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FindFirst&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"tenant_id"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;from&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;From&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;To&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;record&lt;/span&gt; &lt;span class="nc"&gt;ReportRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="nc"&gt;Columns&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;DateTime&lt;/span&gt; &lt;span class="nc"&gt;From&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;DateTime&lt;/span&gt; &lt;span class="nc"&gt;To&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's honest, safe code: columns come from a whitelist, values are parameters, and the tenant comes from the server-side identity rather than the request. If your users' needs stop here, &lt;strong&gt;build it&lt;/strong&gt;. You don't need a product for a column picker over one table.&lt;/p&gt;

&lt;p&gt;The trouble is that this endpoint is the cheapest part of the system, and its existence makes the next requests feel cheap too.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the backlog looks like after launch
&lt;/h2&gt;

&lt;p&gt;Once users can pick columns, the requests that follow are predictable, and each one is a real piece of engineering:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Joins across more tables&lt;/strong&gt; — which means modelling relationships, join types and friendly names, not hard-coding one &lt;code&gt;FROM&lt;/code&gt; clause.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grouping and aggregates&lt;/strong&gt; — &lt;code&gt;SUM&lt;/code&gt;, &lt;code&gt;COUNT&lt;/code&gt;, &lt;code&gt;AVG&lt;/code&gt; by month or by customer, plus totals and sub-totals.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Filters of every type&lt;/strong&gt; — dates with relative ranges ("last 30 days"), dropdowns populated from lookups, "is blank", "in list".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Charts&lt;/strong&gt; — bar, line, pie, and someone will ask for a map.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Saved reports, folders and sharing&lt;/strong&gt; — persistence, ownership, and who can see what.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Exports&lt;/strong&gt; — PDF, Excel, Word and CSV, each of which needs to look right.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scheduling&lt;/strong&gt; — "email me this every Monday", which I covered in &lt;em&gt;&lt;a href="https://dev.to/razisyed/scheduled-pdf-and-excel-report-emails-in-aspnet-core-with-quartznet-37i0"&gt;Scheduled PDF and Excel report emails in ASP.NET Core with Quartz.NET&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dashboards&lt;/strong&gt; — several reports on one page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security that survives all of the above&lt;/strong&gt; — tenant filtering has to be applied to every generated query, every export and every scheduled run, not just the one endpoint you wrote first. That's the subject of &lt;em&gt;&lt;a href="https://dev.to/razisyed/multi-tenant-reporting-in-aspnet-core-row-level-security-your-users-cant-bypass-14lg"&gt;Multi-tenant reporting in ASP.NET Core: row-level security your users can't bypass&lt;/a&gt;&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database protection&lt;/strong&gt; — timeouts, paging, and keeping ad hoc queries off your primary.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these is hard on its own. The cost comes from the combinations: a grouped, filtered, multi-table report exported to Excel on a schedule for a tenant-scoped user is where SQL generation, rendering and security all meet, and that's where the bugs live.&lt;/p&gt;

&lt;h2&gt;
  
  
  The cost model
&lt;/h2&gt;

&lt;p&gt;Here's the model I use. It's in C# because it makes the inputs explicit; it works just as well in a spreadsheet. Everything is in engineer-weeks so salaries stay out of it until the end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;record&lt;/span&gt; &lt;span class="nc"&gt;BuildOption&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;InitialWeeks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;          &lt;span class="c1"&gt;// MVP: builder UI, query generation, saved reports&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;FeatureWeeksPerYear&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;// the backlog above, as users discover it&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;MaintenanceWeeksPerYear&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// bugs, DB/driver upgrades, UI framework upgrades&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;SecurityReviewWeeksPerYear&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;record&lt;/span&gt; &lt;span class="nc"&gt;BuyOption&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;IntegrationWeeks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;      &lt;span class="c1"&gt;// auth wiring, tenant/role mapping, schema curation, styling&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;MaintenanceWeeksPerYear&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// version upgrades, re-curating schema as it changes&lt;/span&gt;
    &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="nc"&gt;LicensePerYear&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;buildWeeks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;buyWeeks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="n"&gt;buyLicense&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;Compare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nc"&gt;BuildOption&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;BuyOption&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;years&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;InitialWeeks&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;years&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FeatureWeeksPerYear&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;MaintenanceWeeksPerYear&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SecurityReviewWeeksPerYear&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IntegrationWeeks&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;years&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;MaintenanceWeeksPerYear&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;LicensePerYear&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;years&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Multiply the weeks by your loaded cost per engineer-week and compare against the license line. Three things make this model honest rather than a sales tool:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Use a multi-year horizon.&lt;/strong&gt; Reporting is never "done". A one-year comparison flatters building because the initial build dominates and the backlog hasn't arrived yet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't set the buy-side maintenance to zero.&lt;/strong&gt; You still upgrade the package, keep the reporting schema in sync with your database, and support your users. It's smaller, not absent.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Price the opportunity cost separately.&lt;/strong&gt; The weeks your team spends on a report builder are weeks not spent on the product your customers chose you for. That's often the deciding number, and it's yours to estimate.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I'm deliberately not giving you default values: they vary too much between teams, and any number I put here would be marketing. Fill it in with your own estimates, then ask the engineer who'll own the feature to add up the backlog list above.&lt;/p&gt;

&lt;h2&gt;
  
  
  What "buy" actually costs you in integration
&lt;/h2&gt;

&lt;p&gt;The buy side isn't free either, so here's what integrating an embedded tool looks like in practice, using Dotnet Report as the concrete example. The report builder runs inside your ASP.NET Core app, and the main integration point is a single method in the API controller that tells it who the current user is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;DotNetReportSettings&lt;/span&gt; &lt;span class="nc"&gt;GetSettings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DotNetReportSettings&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;ApiUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetValue&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"dotNetReport:apiUrl"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;AccountApiToken&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetValue&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"dotNetReport:accountApiToken"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;DataConnectApiToken&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetValue&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"dotNetReport:dataconnectApiToken"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ClientId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FindFirst&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"tenant_id"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Value&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// tenant&lt;/span&gt;
    &lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UserId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FindFirst&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ClaimTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NameIdentifier&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Value&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CurrentUserRole&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FindAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ClaimTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Role&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CanUseAdminMode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ClaimsHelper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;HasAnyRequiredClaim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ClaimsStore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AllowAdminMode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DataFilters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;TenantId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ClientId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// row-level filter, mapped to columns in setup&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Beyond that, the integration work is mostly curation: choosing which tables and views users can see and giving them friendly names on the &lt;code&gt;/dotnetsetup&lt;/code&gt; screen, mapping your roles, and styling the front-end to match your app. The report-builder front-end is source-available on GitHub, so you can read and change how it behaves rather than treating it as a black box.&lt;/p&gt;

&lt;p&gt;You should also understand the architecture you'd be adopting. In Dotnet Report's case, report definitions, folders and schema configuration are managed through its hosted API (the &lt;code&gt;dotNetReport:apiUrl&lt;/code&gt; setting), while the queries themselves run inside your application against your own connection string, so your data stays in your database. The generated SQL comes back encrypted and is decrypted with your &lt;code&gt;privateApiToken&lt;/code&gt; before it executes. Whatever you evaluate, ask the equivalent questions: where do report definitions live, where do queries run, and what happens to your reports if you stop paying.&lt;/p&gt;

&lt;h2&gt;
  
  
  When building is the right call
&lt;/h2&gt;

&lt;p&gt;I'd build, and I'd tell a customer to build, when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The reports are fixed.&lt;/strong&gt; If users need ten known reports with a few filters, that's a feature, not a report builder. Write the ten reports.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The data isn't relational.&lt;/strong&gt; If your data lives in a search index, a time-series store or an event stream, a SQL-based report builder is the wrong shape.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reporting is your product.&lt;/strong&gt; If analytics is what customers pay you for, you want to own every pixel and every query plan.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You can't accept an external dependency&lt;/strong&gt; for report metadata, for regulatory or contractual reasons. Check that before you evaluate anything.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  When buying is the right call
&lt;/h2&gt;

&lt;p&gt;Buying tends to win when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Users want genuinely ad hoc reports&lt;/strong&gt;: their own columns, joins, groupings and charts, and they'll keep asking for more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You're multi-tenant&lt;/strong&gt; and need tenant isolation to be applied consistently across the builder, exports and schedules.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The backlog list above made you wince&lt;/strong&gt;, especially exports, scheduling and dashboards.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reporting is table stakes, not differentiation.&lt;/strong&gt; Customers expect it, but nobody chooses you because of it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For .NET teams in that position, I think Dotnet Report is the best .NET-native option, because it plugs into an ASP.NET Core app the way the code above shows, rather than running as a separate BI server. There are other good embedded-analytics and BI tools with different architectures, and it's worth evaluating them against the same cost model.&lt;/p&gt;

&lt;h2&gt;
  
  
  A practical way to decide
&lt;/h2&gt;

&lt;p&gt;Run the model with two horizons, one year and three years. If building wins both, build, and start with the minimal endpoint at the top of this article. If buying wins at three years but not one, the real question is whether you believe the backlog will arrive; ask your support queue, not your roadmap. And if you do buy, spend the first week on schema curation and security mapping, because that's where an embedded tool succeeds or fails.&lt;/p&gt;

&lt;p&gt;If you want to see how much integration the buy side actually takes, the quickstart sample is a working ASP.NET Core host you can run locally: &lt;strong&gt;&lt;a href="https://github.com/dotnetreport/dotnetreport-aspnetcore-quickstart" rel="noopener noreferrer"&gt;dotnetreport/dotnetreport-aspnetcore-quickstart&lt;/a&gt;&lt;/strong&gt;. The walkthrough is in &lt;em&gt;&lt;a href="https://dev.to/razisyed/add-self-service-ad-hoc-reporting-to-an-aspnet-core-app-without-writing-every-report-yourself-44ng"&gt;Add self-service ad hoc reporting to an ASP.NET Core app&lt;/a&gt;&lt;/em&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Razi Syed builds &lt;a href="https://dotnetreport.com" rel="noopener noreferrer"&gt;Dotnet Report&lt;/a&gt;, an embedded self-service reporting platform for .NET whose report-builder front-end is source-available on GitHub. He writes about adding reporting and analytics to SaaS products without rebuilding them from scratch.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>saas</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Step‑by‑Step Guide to Integrate GroupDocs.Rewriter with ASP.NET Core MVC</title>
      <dc:creator>Aspose</dc:creator>
      <pubDate>Tue, 17 Nov 2026 14:10:18 +0000</pubDate>
      <link>https://dev.to/groupdocs-cloud/step-by-step-guide-to-integrate-groupdocsrewriter-with-aspnet-core-mvc-gog</link>
      <guid>https://dev.to/groupdocs-cloud/step-by-step-guide-to-integrate-groupdocsrewriter-with-aspnet-core-mvc-gog</guid>
      <description>&lt;p&gt;Converting raw text into polished, SEO‑friendly content is a daily challenge for many .NET developers building content‑rich web applications. GroupDocs.Rewriter Cloud SDK for .NET provides a powerful API that rewrites sentences while preserving meaning. This step-by-Step guide to Integrate with ASP.NET Core MVC shows you how to set up the library, configure credentials, implement the rewriting logic in a controller, and render the results in a Razor view.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Use Case Requirements
&lt;/h2&gt;

&lt;p&gt;Enterprises that generate user‑generated articles, product descriptions, or marketing copy often need to improve readability without manual editing. The requirements for such a scenario include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real‑time text rewriting directly from a web form.&lt;/li&gt;
&lt;li&gt;Secure handling of API credentials on the server side.&lt;/li&gt;
&lt;li&gt;Seamless integration with the existing ASP.NET Core MVC pipeline.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using generic string‑manipulation code quickly becomes error‑prone and does not scale, which is why a dedicated document rewriting library is essential.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing GroupDocs.Rewriter Cloud SDK for .NET for the Job
&lt;/h2&gt;

&lt;p&gt;GroupDocs.Rewriter Cloud SDK for .NET offers a REST‑based API that supports multiple languages, customizable rewrite modes, and high‑performance processing. Its key capabilities that match the use case are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;RewriteModeEnum.Rewrite&lt;/strong&gt; - produces a natural‑language rewrite of the input text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DI‑friendly client&lt;/strong&gt; - can be registered as a singleton in the ASP.NET Core service container.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Strong typing and async support&lt;/strong&gt; - fits naturally into modern .NET asynchronous patterns.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The step-by-Step guide to Integrate with ASP.NET Core MVC demonstrates how these capabilities map to the requirements. For detailed API information, see the &lt;a href="https://docs.groupdocs.cloud/rewriter/" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt; and the &lt;a href="https://reference.groupdocs.cloud/rewriter/" rel="noopener noreferrer"&gt;API reference&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing Step‑by‑Step Guide to Integrate with ASP.NET Core MVC
&lt;/h2&gt;

&lt;p&gt;This step-by-Step guide to Integrate with ASP.NET Core MVC will walk you through each required configuration step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install the SDK Package
&lt;/h3&gt;

&lt;p&gt;Add the NuGet package to your project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet add package GroupDocs.Rewriter-Cloud
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also download the binaries from the download page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add Configuration for Rewriter Credentials
&lt;/h3&gt;

&lt;p&gt;Place your AppSid and AppKey in the configuration. The snippet below adds them in‑memory for simplicity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddInMemoryCollection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;KeyValuePair&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"GroupDocsRewriter:AppSid"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"YOUR_APP_SID"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;KeyValuePair&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"GroupDocsRewriter:AppKey"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"YOUR_APP_KEY"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Register the Rewriter API Client in DI
&lt;/h3&gt;

&lt;p&gt;The SDK client is registered as a singleton so it can be injected into controllers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Configure&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;RewriterSettings&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetSection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"GroupDocsRewriter"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddSingleton&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;IRewriterApi&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sp&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetRequiredService&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;IOptions&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;RewriterSettings&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Configuration&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;AppSid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AppSid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;AppKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AppKey&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RewriterApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create the MVC Controller and View Model
&lt;/h3&gt;

&lt;p&gt;The controller receives the original text, calls the Rewriter API, and returns the rewritten result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RewriterController&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Controller&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nc"&gt;IRewriterApi&lt;/span&gt; &lt;span class="n"&gt;_rewriterApi&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;RewriterController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IRewriterApi&lt;/span&gt; &lt;span class="n"&gt;rewriterApi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_rewriterApi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rewriterApi&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;HttpGet&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;IActionResult&lt;/span&gt; &lt;span class="nc"&gt;Index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RewriterViewModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;HttpPost&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;IActionResult&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;RewriterViewModel&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nc"&gt;ModelState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsValid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;rewriteRequest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RewriteRequest&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;Text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;InputText&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nc"&gt;Language&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"en"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nc"&gt;TargetLanguage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"en"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nc"&gt;RewriteMode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RewriteModeEnum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rewrite&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nc"&gt;RewriteResponse&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_rewriterApi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RewriteAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rewriteRequest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OutputText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Empty&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The accompanying view model holds the input and output strings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RewriterViewModel&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Required&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Original Text"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;InputText&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Empty&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Rewritten Text"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;OutputText&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Empty&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Build the Razor View for Text Input and Output
&lt;/h3&gt;

&lt;p&gt;The Razor page presents a simple form and displays the rewritten text when available.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="nd"&gt;@model&lt;/span&gt; &lt;span class="nc"&gt;RewriterViewModel&lt;/span&gt;
@&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;ViewData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Title"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Text Rewriter"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nd"&gt;@ViewData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Title"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;form&lt;/span&gt; &lt;span class="n"&gt;asp&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Index"&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"post"&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"form-horizontal"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"form-group"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt; &lt;span class="n"&gt;asp&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"InputText"&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"control-label"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;textarea&lt;/span&gt; &lt;span class="n"&gt;asp&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"InputText"&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"form-control"&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"6"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;textarea&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;span&lt;/span&gt; &lt;span class="n"&gt;asp&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;validation&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"InputText"&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"text-danger"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"form-group"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;button&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"submit"&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"btn btn-primary"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Rewrite&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nd"&gt;@if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsNullOrWhiteSpace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OutputText&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;hr&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h4&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Rewritten&lt;/span&gt; &lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h4&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;textarea&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"form-control"&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"6"&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nd"&gt;@Model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OutputText&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;textarea&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nd"&gt;@section&lt;/span&gt; &lt;span class="nc"&gt;Scripts&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    @&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;Html&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RenderPartialAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"_ValidationScriptsPartial"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Full Working Example for Document Rewriting in ASP.NET Core MVC
&lt;/h2&gt;

&lt;p&gt;The example below contains the complete source files needed to run the solution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ---------------------------------------------------&lt;/span&gt;
&lt;span class="c1"&gt;// Program.cs&lt;/span&gt;
&lt;span class="c1"&gt;// ---------------------------------------------------&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;Microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AspNetCore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Builder&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;Microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Extensions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Configuration&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;Microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Extensions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DependencyInjection&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;Microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Extensions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Hosting&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;Microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Extensions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Options&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;GroupDocs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rewriter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Cloud&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sdk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Api&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;GroupDocs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rewriter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Cloud&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sdk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;GroupDocs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rewriter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Cloud&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sdk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Requests&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;GroupDocs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rewriter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Cloud&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sdk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Tasks&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;WebApplication&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Add configuration for GroupDocs Rewriter credentials&lt;/span&gt;
&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddInMemoryCollection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;KeyValuePair&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"GroupDocsRewriter:AppSid"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"YOUR_APP_SID"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;KeyValuePair&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"GroupDocsRewriter:AppKey"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"YOUR_APP_KEY"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Configure&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;RewriterSettings&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetSection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"GroupDocsRewriter"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Register GroupDocs Rewriter API client in DI&lt;/span&gt;
&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddSingleton&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;IRewriterApi&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sp&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetRequiredService&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;IOptions&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;RewriterSettings&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Configuration&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;AppSid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AppSid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;AppKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AppKey&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RewriterApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddControllersWithViews&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsDevelopment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UseExceptionHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/Home/Error"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UseStaticFiles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UseRouting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UseAuthorization&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;MapControllerRoute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"default"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"{controller=Rewriter}/{action=Index}/{id?}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// ---------------------------------------------------&lt;/span&gt;
&lt;span class="c1"&gt;// RewriterSettings.cs&lt;/span&gt;
&lt;span class="c1"&gt;// ---------------------------------------------------&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RewriterSettings&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;AppSid&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Empty&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;AppKey&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Empty&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// ---------------------------------------------------&lt;/span&gt;
&lt;span class="c1"&gt;// Models/RewriterViewModel.cs&lt;/span&gt;
&lt;span class="c1"&gt;// ---------------------------------------------------&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ComponentModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DataAnnotations&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RewriterViewModel&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Required&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Original Text"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;InputText&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Empty&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Rewritten Text"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;OutputText&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Empty&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// ---------------------------------------------------&lt;/span&gt;
&lt;span class="c1"&gt;// Controllers/RewriterController.cs&lt;/span&gt;
&lt;span class="c1"&gt;// ---------------------------------------------------&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;Microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AspNetCore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Mvc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Tasks&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RewriterController&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Controller&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nc"&gt;IRewriterApi&lt;/span&gt; &lt;span class="n"&gt;_rewriterApi&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;RewriterController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IRewriterApi&lt;/span&gt; &lt;span class="n"&gt;rewriterApi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_rewriterApi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rewriterApi&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;HttpGet&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;IActionResult&lt;/span&gt; &lt;span class="nc"&gt;Index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RewriterViewModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;HttpPost&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;IActionResult&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;RewriterViewModel&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nc"&gt;ModelState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsValid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// Build request for the Rewriter API&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;rewriteRequest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RewriteRequest&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;Text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;InputText&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nc"&gt;Language&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"en"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;               &lt;span class="c1"&gt;// source language&lt;/span&gt;
            &lt;span class="nc"&gt;TargetLanguage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"en"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;         &lt;span class="c1"&gt;// target language (same for rewriting)&lt;/span&gt;
            &lt;span class="nc"&gt;RewriteMode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RewriteModeEnum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rewrite&lt;/span&gt; &lt;span class="c1"&gt;// choose rewrite mode&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Call the API&lt;/span&gt;
        &lt;span class="nc"&gt;RewriteResponse&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_rewriterApi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RewriteAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rewriteRequest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Populate the view model with the rewritten text&lt;/span&gt;
        &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OutputText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Empty&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// ---------------------------------------------------&lt;/span&gt;
&lt;span class="c1"&gt;// Views/Rewriter/Index.cshtml&lt;/span&gt;
&lt;span class="c1"&gt;// ---------------------------------------------------&lt;/span&gt;
&lt;span class="nd"&gt;@model&lt;/span&gt; &lt;span class="nc"&gt;RewriterViewModel&lt;/span&gt;
@&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;ViewData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Title"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Text Rewriter"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nd"&gt;@ViewData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Title"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;form&lt;/span&gt; &lt;span class="n"&gt;asp&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Index"&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"post"&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"form-horizontal"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"form-group"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt; &lt;span class="n"&gt;asp&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"InputText"&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"control-label"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;textarea&lt;/span&gt; &lt;span class="n"&gt;asp&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"InputText"&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"form-control"&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"6"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;textarea&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;span&lt;/span&gt; &lt;span class="n"&gt;asp&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;validation&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"InputText"&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"text-danger"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"form-group"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;button&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"submit"&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"btn btn-primary"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Rewrite&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nd"&gt;@if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsNullOrWhiteSpace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OutputText&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;hr&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h4&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Rewritten&lt;/span&gt; &lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h4&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;textarea&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"form-control"&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"6"&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nd"&gt;@Model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OutputText&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;textarea&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nd"&gt;@section&lt;/span&gt; &lt;span class="nc"&gt;Scripts&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    @&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;Html&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RenderPartialAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"_ValidationScriptsPartial"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This code example demonstrates the core functionality. Before using it in your project, make sure to update any file paths and configuration values to match your actual environment, verify that all required dependencies are properly installed, and test thoroughly in your development environment. If you encounter any issues, please refer to the &lt;a href="https://docs.groupdocs.cloud/rewriter/" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt; or reach out to the &lt;a href="https://forum.groupdocs.cloud/c/rewriter/34" rel="noopener noreferrer"&gt;support team&lt;/a&gt; for assistance.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Executing Document Rewriting Via REST API Using cURL
&lt;/h2&gt;

&lt;p&gt;Below is a quick cURL workflow that performs the same rewrite operation via the GroupDocs Rewriter REST endpoints.&lt;/p&gt;

&lt;h3&gt;
  
  
  Authenticate and Get Access Token
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST &lt;span class="s2"&gt;"https://api.groupdocs.cloud/v1/auth/token"&lt;/span&gt; \
     -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
     -d &lt;span class="s1"&gt;'{"client_id":"YOUR_CLIENT_ID","client_secret":"YOUR_CLIENT_SECRET"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response returns an &lt;code&gt;access_token&lt;/code&gt; that you will use in subsequent calls.&lt;/p&gt;

&lt;h3&gt;
  
  
  Upload the Source Text (optional for large files)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST &lt;span class="s2"&gt;"https://api.groupdocs.cloud/v1/storage/file/upload"&lt;/span&gt; \
     -H &lt;span class="s2"&gt;"Authorization: Bearer YOUR_ACCESS_TOKEN"&lt;/span&gt; \
     -F &lt;span class="s2"&gt;"file=@input.txt"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Execute the Rewrite Operation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST &lt;span class="s2"&gt;"https://api.groupdocs.cloud/v1/rewriter/rewrite"&lt;/span&gt; \
     -H &lt;span class="s2"&gt;"Authorization: Bearer YOUR_ACCESS_TOKEN"&lt;/span&gt; \
     -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
     -d &lt;span class="s1"&gt;'{
           "text": "Your original text goes here.",
           "language": "en",
           "targetLanguage": "en",
           "rewriteMode": "Rewrite"
         }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;a href="https://docs.fileformat.com/web/json/" rel="noopener noreferrer"&gt;JSON&lt;/a&gt; response contains the rewritten text in the &lt;code&gt;result.text&lt;/code&gt; field.&lt;/p&gt;

&lt;h3&gt;
  
  
  Download the Result (if you stored it as a file)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X GET &lt;span class="s2"&gt;"https://api.groupdocs.cloud/v1/storage/file/download?path=output.txt"&lt;/span&gt; \
     -H &lt;span class="s2"&gt;"Authorization: Bearer YOUR_ACCESS_TOKEN"&lt;/span&gt; \
     -o rewritten.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For more details on request parameters and response formats, see the &lt;a href="https://docs.groupdocs.cloud/rewriter/" rel="noopener noreferrer"&gt;official API documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Integrating the GroupDocs.Rewriter Cloud SDK for .NET into an ASP.NET Core MVC project is straightforward once you follow this step-by-Step guide to Integrate with ASP.NET Core MVC. The library handles the heavy lifting of natural‑language rewriting, letting you focus on UI and business logic. Remember to secure your AppSid and AppKey, use the temporary license for evaluation, and upgrade to a full license for production workloads. With the code and cURL examples in hand, you can now add intelligent text rewriting to any .NET web application.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQs
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;How does the step-by-Step guide to Integrate with ASP.NET Core MVC handle error responses from the API?&lt;/strong&gt; &lt;br&gt;
The controller example checks &lt;code&gt;ModelState.IsValid&lt;/code&gt; before calling the API and captures the &lt;code&gt;RewriteResponse&lt;/code&gt;. If the API returns an error, the &lt;code&gt;response&lt;/code&gt; object will be null, and the view will simply show an empty output. For detailed error handling, consult the &lt;a href="https://docs.groupdocs.cloud/rewriter/" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I rewrite documents other than plain text, such as &lt;a href="https://docs.fileformat.com/word-processing/docx/" rel="noopener noreferrer"&gt;DOCX&lt;/a&gt; or &lt;a href="https://docs.fileformat.com/pdf" rel="noopener noreferrer"&gt;PDF&lt;/a&gt;, using the same approach?&lt;/strong&gt; &lt;br&gt;
Yes. The Rewriter API accepts raw text extracted from supported formats. You can first use GroupDocs.Parser or GroupDocs.Conversion to extract text, then pass it to the rewrite endpoint. Both SDKs are listed in the GroupDocs product family.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is it possible to run the rewrite operation asynchronously in a high‑traffic web site?&lt;/strong&gt; &lt;br&gt;
Absolutely. The controller uses &lt;code&gt;await _rewriterApi.RewriteAsync(...)&lt;/code&gt;, which is fully asynchronous and scales with ASP.NET Core’s async pipeline. This fits the pattern demonstrated in the step-by-Step guide to Integrate with ASP.NET Core MVC.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where can I obtain a temporary license for testing?&lt;/strong&gt; &lt;br&gt;
A temporary license is available from the temporary license page. It lets you evaluate the SDK without committing to a purchase.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further Reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://blog.groupdocs.cloud/rewriter/paraphrase-documents-online/" rel="noopener noreferrer"&gt;Rephrase and Rewrite Documents in .NET | Rewrite Paragraphs online in C#&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.groupdocs.cloud/rewriter/summarize-document-content-csharp/" rel="noopener noreferrer"&gt;Summarize Document Content in C# .NET | Document Summarization API&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>dotnet</category>
      <category>api</category>
      <category>cloud</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>System.Threading.Channels in .NET 10, Measured: The Write Said True and the Item Was Gone</title>
      <dc:creator>Juan Gómez</dc:creator>
      <pubDate>Tue, 17 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/jgomezdev/systemthreadingchannels-in-net-10-measured-the-write-said-true-and-the-item-was-gone-3p20</link>
      <guid>https://dev.to/jgomezdev/systemthreadingchannels-in-net-10-measured-the-write-said-true-and-the-item-was-gone-3p20</guid>
      <description>&lt;h1&gt;
  
  
  System.Threading.Channels in .NET 10, Measured: The Write Said True and the Item Was Gone
&lt;/h1&gt;

&lt;p&gt;When a producer is faster than its consumer, something has to give. The queue between them can grow without limit, the producer can be made to wait, or items can be thrown away. &lt;code&gt;System.Threading.Channels&lt;/code&gt; makes you pick one of those, which is exactly what it should do. What surprised me is how two of the choices report it: a bounded channel in a drop mode answers &lt;code&gt;true&lt;/code&gt; to the write of an item it has just thrown away.&lt;/p&gt;

&lt;p&gt;I measured an unbounded channel and all four modes of a bounded one under the same load on .NET 10, then broke a three-stage pipeline in the middle to see who notices. Short answer: nobody, unless every stage is wired to tell the others.&lt;/p&gt;

&lt;p&gt;Every example below is a .NET 10 file-based app: save the block as a &lt;code&gt;.cs&lt;/code&gt; file and run it with &lt;code&gt;dotnet run -c Release &amp;lt;file&amp;gt;.cs&lt;/code&gt;, with no project file. The numbers come from .NET 10.0.15 on an 8-core laptop. All of them, plus the pipeline variants the text describes without printing, are in &lt;a href="https://github.com/Juxn89/dotnet-10-channels" rel="noopener noreferrer"&gt;dotnet-10-channels&lt;/a&gt; on GitHub, with a script that checks each behaviour.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy4rmrj6mr3nxfngvzm7p.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy4rmrj6mr3nxfngvzm7p.jpg" alt="A robotic arm places a cube into a three-slot tray that is already full, under a green checkmark, while a cube falls off the far end of the tray into a bin" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A channel in one paragraph
&lt;/h2&gt;

&lt;p&gt;A channel is a thread-safe queue with two ends: a &lt;code&gt;ChannelWriter&amp;lt;T&amp;gt;&lt;/code&gt; that producers write to and a &lt;code&gt;ChannelReader&amp;lt;T&amp;gt;&lt;/code&gt; that consumers read from. Both ends are async. A reader on an empty channel awaits without holding a thread, and so does a writer on a full one. &lt;code&gt;Channel.CreateUnbounded&amp;lt;T&amp;gt;()&lt;/code&gt; never fills up. &lt;code&gt;Channel.CreateBounded&amp;lt;T&amp;gt;(capacity)&lt;/code&gt; does, and its &lt;code&gt;FullMode&lt;/code&gt; decides what happens then. When the producer is done it calls &lt;code&gt;Writer.Complete()&lt;/code&gt;, and &lt;code&gt;ReadAllAsync()&lt;/code&gt; ends once the channel is complete and empty. It has shipped with .NET since .NET Core 3.0, so there is no package to install.&lt;/p&gt;

&lt;h2&gt;
  
  
  Five writes into a channel that holds three
&lt;/h2&gt;

&lt;p&gt;The quickest way to see the four full modes is to write five items into a channel of three and read back what is left. &lt;code&gt;itemDropped&lt;/code&gt; is an optional callback, added in .NET 6, that the channel calls with every item it throws away:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Channels&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Five writes into a channel that holds three, once per full mode.&lt;/span&gt;
&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BoundedChannelFullMode&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nc"&gt;Enum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetValues&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BoundedChannelFullMode&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;dropped&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Channel&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateBounded&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BoundedChannelOptions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;capacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;FullMode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;itemDropped&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;dropped&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;accepted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;accepted&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Writer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TryWrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Writer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Complete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;read&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReadAllAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"{mode,-10}  TryWrite: {string.Join("&lt;/span&gt; &lt;span class="s2"&gt;", accepted),-26}  read: [{string.Join("&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;", read)}]  itemDropped: [{string.Join("&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;", dropped)}]"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Wait        TryWrite: True True True False False  read: [1, 2, 3]  itemDropped: []
DropNewest  TryWrite: True True True True True    read: [1, 2, 5]  itemDropped: [3, 4]
DropOldest  TryWrite: True True True True True    read: [3, 4, 5]  itemDropped: [1, 2]
DropWrite   TryWrite: True True True True True    read: [1, 2, 3]  itemDropped: [4, 5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things in those four lines are worth a second look.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In the three drop modes, every write returned &lt;code&gt;True&lt;/code&gt;.&lt;/strong&gt; Two items out of five are gone in each, and the writer was told it succeeded. &lt;code&gt;WriteAsync&lt;/code&gt; behaves the same way: in the load test below, all 20,000 calls completed normally, including the thousands whose item was dropped. The &lt;code&gt;itemDropped&lt;/code&gt; callback is the only place the channel tells you, and it is easy to miss, because it is an optional parameter on a factory method. It also runs on the writer's thread, during the write and outside the channel's lock, so with several producers it can run on several threads at once. Count in it with something like the &lt;code&gt;Interlocked.Increment&lt;/code&gt; in the load test below; the &lt;code&gt;List&lt;/code&gt; in this example is safe only because one thread does all the writing. If that sounds familiar, it is the same lesson as &lt;code&gt;channel.publish&lt;/code&gt; returning &lt;code&gt;true&lt;/code&gt; in &lt;a href="https://dev.to/jgomezdev/rabbitmq-from-fundamentals-to-production-part-2-building-a-scalable-service-4nk2"&gt;RabbitMQ from Fundamentals to Production, Part 2: Building a Scalable Service&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;DropNewest&lt;/code&gt; does not drop the item you are writing.&lt;/strong&gt; It drops the newest item &lt;em&gt;already in the channel&lt;/em&gt; to make room for it: writing 4 evicted 3, and writing 5 evicted 4. The channel keeps the oldest items plus the very last one. &lt;code&gt;DropWrite&lt;/code&gt; is the mode that refuses the incoming item.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In &lt;code&gt;Wait&lt;/code&gt; mode, &lt;code&gt;TryWrite&lt;/code&gt; does not wait.&lt;/strong&gt; It returns &lt;code&gt;False&lt;/code&gt; when the channel is full, and only &lt;code&gt;WriteAsync&lt;/code&gt; waits for space. A producer that calls &lt;code&gt;TryWrite&lt;/code&gt; and ignores the result loses items in the one mode whose name promises it never will.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same choice under load
&lt;/h2&gt;

&lt;p&gt;Five items show what each mode does, not what it costs. For that I simulated the sensor gateway of a refrigerated truck: 20,000 temperature readings, each received in 20 µs and stored in 200 µs, so the producer is ten times faster than the consumer. The capacity is 1,000. Both costs are a busy-wait, a stand-in for real work with a steady, known cost, so that the channel is the only thing that changes between rows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Diagnostics&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Channels&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;Total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20_000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;Capacity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1_000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;TimeSpan&lt;/span&gt; &lt;span class="n"&gt;receiveCost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FromMicroseconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// reading one message off the socket&lt;/span&gt;
&lt;span class="nc"&gt;TimeSpan&lt;/span&gt; &lt;span class="n"&gt;storeCost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FromMicroseconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;// inserting it into the database&lt;/span&gt;

&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"{Total:N0} readings, received in {receiveCost.TotalMicroseconds} µs and stored in {storeCost.TotalMicroseconds} µs each, capacity {Capacity:N0}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"{"&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="s2"&gt;",-10} {"&lt;/span&gt;&lt;span class="n"&gt;producer&lt;/span&gt;&lt;span class="s2"&gt;",8} {"&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="s2"&gt;",7} {"&lt;/span&gt;&lt;span class="n"&gt;stored&lt;/span&gt;&lt;span class="s2"&gt;",8} {"&lt;/span&gt;&lt;span class="n"&gt;dropped&lt;/span&gt;&lt;span class="s2"&gt;",8} {"&lt;/span&gt;&lt;span class="n"&gt;median&lt;/span&gt; &lt;span class="n"&gt;wait&lt;/span&gt;&lt;span class="s2"&gt;",12} {"&lt;/span&gt;&lt;span class="n"&gt;max&lt;/span&gt; &lt;span class="n"&gt;wait&lt;/span&gt;&lt;span class="s2"&gt;",9}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;MeasureAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Unbounded"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateUnbounded&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Reading&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;UnboundedChannelOptions&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;SingleReader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;dropped&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BoundedChannelFullMode&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nc"&gt;Enum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetValues&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BoundedChannelFullMode&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;dropped&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Channel&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Reading&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateBounded&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Reading&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BoundedChannelOptions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Capacity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;FullMode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;itemDropped&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Interlocked&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;dropped&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;MeasureAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dropped&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Interlocked&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;dropped&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="nc"&gt;MeasureAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Channel&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Reading&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Func&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;long&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;dropped&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;stored&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;waits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Total&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// from receiving each stored reading to storing it&lt;/span&gt;
    &lt;span class="nc"&gt;Stopwatch&lt;/span&gt; &lt;span class="n"&gt;clock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Stopwatch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StartNew&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="n"&gt;consumer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Reading&lt;/span&gt; &lt;span class="n"&gt;reading&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReadAllAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;Work&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;storeCost&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;waits&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;stored&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Stopwatch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetElapsedTime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReceivedAt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;sequence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;sequence&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nc"&gt;Total&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;sequence&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Work&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;receiveCost&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Writer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Reading&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"truck-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;4.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Stopwatch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetTimestamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nc"&gt;TimeSpan&lt;/span&gt; &lt;span class="n"&gt;producer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;clock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Elapsed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Writer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Complete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;consumer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// after this, the counters the consumer wrote are safe to read here&lt;/span&gt;
    &lt;span class="nc"&gt;TimeSpan&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;clock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Elapsed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;waits&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stored&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"{mode,-10} {producer.TotalSeconds,7:F2}s {total.TotalSeconds,6:F2}s {stored,8:N0} {dropped(),8:N0} {waits[stored / 2].TotalMilliseconds,9:N1} ms {waits[stored - 1].TotalMilliseconds,6:N0} ms"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Spins for a fixed time: a stand-in for real work with a steady, known cost.&lt;/span&gt;
&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;Work&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;TimeSpan&lt;/span&gt; &lt;span class="n"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;until&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Stopwatch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetTimestamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;long&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TotalSeconds&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nc"&gt;Stopwatch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Frequency&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Stopwatch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetTimestamp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;until&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;record&lt;/span&gt; &lt;span class="nc"&gt;Reading&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="nc"&gt;Sequence&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;SensorId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;Celsius&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="nc"&gt;ReceivedAt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;SingleReader = true&lt;/code&gt; tells the unbounded channel that only one read will ever be in progress at a time, which a single &lt;code&gt;await foreach&lt;/code&gt; loop guarantees even when its awaits resume on different threads. It lets &lt;code&gt;CreateUnbounded&lt;/code&gt; pick a faster implementation, and nothing checks that it is true, so set it only when it is. The bounded channel has no such variant in .NET 10: &lt;code&gt;CreateBounded&lt;/code&gt; ignores both &lt;code&gt;SingleReader&lt;/code&gt; and &lt;code&gt;SingleWriter&lt;/code&gt;, so I left them off.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;20,000 readings, received in 20 µs and stored in 200 µs each, capacity 1,000
mode       producer   total   stored  dropped  median wait  max wait
Unbounded     0.42s   4.04s   20,000        0   1,813.4 ms  3,621 ms
Wait          3.86s   4.06s   20,000        0     203.3 ms    204 ms
DropNewest    0.41s   0.61s    3,018   16,982     200.4 ms    202 ms
DropOldest    0.40s   0.60s    3,012   16,988      20.4 ms    201 ms
DropWrite     0.40s   0.60s    3,012   16,988     200.6 ms    201 ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is one run of three. Another matched it on every row, to within 0.02 seconds and 25 stored readings. In the third, something else on the laptop slowed the consumer during the drop modes: they stored between 1,673 and 2,720 readings instead of about 3,000, and their median waits went up, though &lt;code&gt;DropOldest&lt;/code&gt;'s was still the lowest (53 ms against 236 and 508). The times move between runs; what each mode does with the readings does not.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unbounded lost nothing and never slowed the producer.&lt;/strong&gt; It moved the problem into memory instead. When the burst ended after 0.42 seconds, the consumer had stored fewer than 2,500 of the 20,000 readings, and the rest sat in the queue: a median wait of 1.8 seconds each. Under a burst that does not end, that queue grows until the process runs out of memory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Wait&lt;/code&gt; lost nothing and made the producer pay.&lt;/strong&gt; It took about 4 seconds instead of 0.4, the pace of the consumer. Each reading waited a median of 203 ms, which is the capacity times the cost of storing one reading: 1,000 × 200 µs. That is the latency you choose when you choose the capacity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The three drop modes kept the producer at full speed and threw away 85% of the readings.&lt;/strong&gt; Each stored about 3,000: the 2,000 or so the consumer could store in 0.4 seconds at 200 µs each, plus the 1,000 left in the buffer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Only &lt;code&gt;DropOldest&lt;/code&gt; kept the consumer on fresh data.&lt;/strong&gt; Its median wait was 20 ms, against about 200 ms for the other two. Its buffer always holds the last 1,000 readings to arrive, and one arrives every 20 µs, so the oldest of them, the one the consumer takes next, arrived 1,000 × 20 µs = 20 ms earlier. In &lt;code&gt;DropNewest&lt;/code&gt; and &lt;code&gt;DropWrite&lt;/code&gt;, a reading gets in only when the consumer frees a slot, and then waits for the 1,000 ahead of it to be stored: 1,000 × 200 µs, 200 ms. The maximum is about 200 ms in all three because it measures the buffer draining after the producer stopped.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the right mode depends on the data, not on the speed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Wait&lt;/code&gt;&lt;/strong&gt; for anything you cannot lose: orders, payments, messages you will acknowledge to a broker. The producer slows down, and whatever feeds it has to slow down too.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;DropOldest&lt;/code&gt;&lt;/strong&gt; for state where the latest value replaces the earlier ones, such as a temperature or a position, as long as the channel carries a single source. A channel has no keys: with a whole fleet in one channel, a quiet truck's only reading is often the oldest one, and it is the one that goes. For many sources, keep a channel per source, or a dictionary with the latest value for each.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;DropWrite&lt;/code&gt;&lt;/strong&gt; for best-effort data where any sample will do, such as analytics events. It keeps what is already queued and refuses what is new. &lt;code&gt;DropNewest&lt;/code&gt; behaved almost the same under load; the only difference is which item goes, the incoming one or the last one queued.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In any drop mode, count &lt;code&gt;itemDropped&lt;/code&gt;&lt;/strong&gt; and export it as a metric. A reading that was dropped and never counted looks exactly like one that was never sent.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5j7atsqrdr7kwj0xx0u2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5j7atsqrdr7kwj0xx0u2.jpg" alt="Four trays already holding three numbered cubes, each with a new cube arriving: the first shut by a gate with an hourglass, one dropping its oldest cube out of the far end, and one knocking the incoming cube away" width="799" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A pipeline where one stage throws
&lt;/h2&gt;

&lt;p&gt;Channels are at their best connecting stages: each stage reads from one channel and writes to the next. Here is the gateway as three stages, &lt;code&gt;receive → parse → store&lt;/code&gt;, with a bounded channel between each pair. At reading 5,000, the probe on truck 17 disconnects and the gateway sends &lt;code&gt;N/A&lt;/code&gt; instead of a temperature:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Globalization&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Channels&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// receive → parse → store, with a bounded channel between each pair of stages.&lt;/span&gt;
&lt;span class="nc"&gt;Channel&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateBounded&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Channel&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Reading&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;readings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateBounded&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Reading&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;received&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;parsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stored&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="n"&gt;receive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;sequence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;sequence&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10_000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;sequence&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Truck 17's probe disconnects once, and the gateway sends N/A instead of a temperature.&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sequence&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;5_000&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; $&lt;span class="s2"&gt;"{sequence};truck-17;N/A"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; $&lt;span class="s2"&gt;"{sequence};truck-17;4.2"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Writer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Interlocked&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;received&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Writer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Complete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="n"&gt;parse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReadAllAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;fields&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;';'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Reading&lt;/span&gt; &lt;span class="n"&gt;reading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;long&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;CultureInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;InvariantCulture&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;NumberStyles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;CultureInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;InvariantCulture&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;readings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Writer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reading&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Interlocked&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;readings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Writer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Complete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Reading&lt;/span&gt; &lt;span class="n"&gt;reading&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;readings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReadAllAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nc"&gt;Interlocked&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;stored&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WhenAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;receive&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WhenAny&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pipeline&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FromSeconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;pipeline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"Still running after 10 s. receive: {receive.Status}, parse: {parse.Status}, store: {store.Status}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"received {Volatile.Read(ref received):N0}, parsed {Volatile.Read(ref parsed):N0}, stored {Volatile.Read(ref stored):N0}, waiting in lines: {lines.Reader.Count}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;record&lt;/span&gt; &lt;span class="nc"&gt;Reading&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="nc"&gt;Sequence&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;SensorId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;Celsius&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Still running after 10 s. receive: WaitingForActivation, parse: Faulted, store: WaitingForActivation
received 5,101, parsed 5,000, stored 5,000, waiting in lines: 100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;parse&lt;/code&gt; threw a &lt;code&gt;FormatException&lt;/code&gt; on reading 5,000, and its task is &lt;code&gt;Faulted&lt;/code&gt;. Nothing else knows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;receive&lt;/code&gt; is blocked.&lt;/strong&gt; It filled &lt;code&gt;lines&lt;/code&gt; with the next 100 lines and is waiting in &lt;code&gt;WriteAsync&lt;/code&gt; for a slot that will never free up, because nothing reads &lt;code&gt;lines&lt;/code&gt; anymore.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;store&lt;/code&gt; is waiting&lt;/strong&gt; for readings that will never come. &lt;code&gt;readings&lt;/code&gt; was never completed, so its &lt;code&gt;ReadAllAsync&lt;/code&gt; cannot tell "no data yet" from "no more data".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Task.WhenAll&lt;/code&gt; cannot help.&lt;/strong&gt; It waits for all three tasks, two of them never finish, and the exception it would rethrow stays inside a faulted task.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No crash, no log line, no CPU: as failures go, a very calm one. Without the 10-second watchdog at the end, the process would sit there until someone restarts it, and in a service it would look like a consumer that stalled for no reason.&lt;/p&gt;

&lt;p&gt;The usual advice is to complete the writer in a &lt;code&gt;finally&lt;/code&gt;, so the next stage is never left waiting. I measured that too, with each stage's loop wrapped in &lt;code&gt;try { … } finally { writer.Complete(); }&lt;/code&gt; and nothing else changed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Still running after 10 s. receive: WaitingForActivation, parse: Faulted, store: RanToCompletion
received 5,101, parsed 5,000, stored 5,000, waiting in lines: 100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;store&lt;/code&gt; now ends as &lt;code&gt;RanToCompletion&lt;/code&gt;, that is, successfully, having stored 5,000 of the 10,000 readings as if the stream had ended there. And &lt;code&gt;receive&lt;/code&gt; still hangs, because a &lt;code&gt;finally&lt;/code&gt; that completes the channel &lt;em&gt;after&lt;/em&gt; a stage does nothing for the stage &lt;em&gt;before&lt;/em&gt; it. The hang is still there, and now the stage after it reports success on half the data.&lt;/p&gt;

&lt;p&gt;A stage that fails has to tell both sides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Downstream&lt;/strong&gt;, complete its output with the exception: &lt;code&gt;writer.Complete(exception)&lt;/code&gt;. The next stage's &lt;code&gt;ReadAllAsync&lt;/code&gt; reads what is left in the channel, then throws.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Upstream&lt;/strong&gt;, cancel the stage before it. Whatever that stage is waiting on, a full channel, an empty one or its own source, throws &lt;code&gt;OperationCanceledException&lt;/code&gt; instead of waiting forever, and that stage, stopping in turn, cancels the one before it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The pipeline, fixed
&lt;/h2&gt;

&lt;p&gt;Every stage below runs through one helper that does both. Two other things changed. A malformed line is now counted and skipped, because bad data is not a reason to stop a pipeline. And to trigger the failure path, &lt;code&gt;store&lt;/code&gt; throws when it reaches reading 7,000, the way a database connection eventually drops:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Diagnostics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CodeAnalysis&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Globalization&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Channels&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// One token per stage, for everything that stage waits on. Only the stage after it cancels it,&lt;/span&gt;
&lt;span class="c1"&gt;// when that stage fails, so the stop travels back to the first stage, and the stages after a&lt;/span&gt;
&lt;span class="c1"&gt;// failure are never cancelled: they read what is left, then get the exception. In an app, link&lt;/span&gt;
&lt;span class="c1"&gt;// all three to the shutdown token too.&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;CancellationTokenSource&lt;/span&gt; &lt;span class="n"&gt;stopReceive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stopParse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stopStore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Channel&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateBounded&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Channel&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Reading&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;readings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateBounded&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Reading&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;received&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rejected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;parsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stored&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="n"&gt;receive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RunStageAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stopReceive&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stopPrevious&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Writer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TryComplete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;cancellation&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;sequence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;sequence&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10_000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;sequence&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sequence&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;5_000&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; $&lt;span class="s2"&gt;"{sequence};truck-17;N/A"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; $&lt;span class="s2"&gt;"{sequence};truck-17;4.2"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Writer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancellation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Interlocked&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;received&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="n"&gt;parse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RunStageAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stopParse&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stopPrevious&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;stopReceive&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;readings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Writer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TryComplete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;cancellation&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReadAllAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cancellation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// A malformed line is bad data, not a broken pipeline: count it and move on.&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nc"&gt;TryParse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="nc"&gt;Reading&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;reading&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;Interlocked&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;rejected&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;readings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Writer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancellation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Interlocked&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RunStageAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stopStore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stopPrevious&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;stopParse&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;cancellation&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Reading&lt;/span&gt; &lt;span class="n"&gt;reading&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;readings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReadAllAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cancellation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// The failure nobody planned for.&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sequence&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;7_000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;IOException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Database connection lost."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Interlocked&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;stored&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WhenAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;receive&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Pipeline finished."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"Pipeline stopped: {ex.GetType().Name}: {ex.Message}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"receive: {receive.Status}, parse: {parse.Status}, store: {store.Status}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"received {received:N0}, rejected {rejected}, parsed {parsed:N0}, stored {stored:N0}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Runs one stage on the thread pool. When it ends, it completes the stage's output channel,&lt;/span&gt;
&lt;span class="c1"&gt;// passing on the exception if it failed, and a failure also cancels the stage before it.&lt;/span&gt;
&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="nc"&gt;RunStageAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CancellationTokenSource&lt;/span&gt; &lt;span class="n"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;CancellationTokenSource&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;stopPrevious&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Action&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="o"&gt;?&amp;gt;?&lt;/span&gt; &lt;span class="n"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Func&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;CancellationToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;body&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;complete&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;OperationCanceledException&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsCancellationRequested&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Cancelled by something other than this pipeline, such as an HTTP timeout. That is a&lt;/span&gt;
        &lt;span class="c1"&gt;// failure: wrapped, it ends the task as Faulted and cannot be mistaken for a stop.&lt;/span&gt;
        &lt;span class="nc"&gt;StageFailedException&lt;/span&gt; &lt;span class="n"&gt;failure&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;FailAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;failure&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;failure&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;FailAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="nc"&gt;FailAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;failure&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;complete&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;failure&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;              &lt;span class="c1"&gt;// the next stage reads what is left, then gets the failure&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stopPrevious&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;stopPrevious&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CancelAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// the stage before stops, wherever it is waiting&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nc"&gt;TryParse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;NotNullWhen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="nc"&gt;Reading&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;reading&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;fields&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;';'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// NumberStyles.Float, not the default, which also accepts a thousands separator and would&lt;/span&gt;
    &lt;span class="c1"&gt;// read "4,2" as 42. IsFinite rejects "NaN" and "Infinity".&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Length&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
        &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TryParse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;CultureInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;InvariantCulture&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TryParse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;NumberStyles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;CultureInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;InvariantCulture&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;celsius&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsFinite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;celsius&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;reading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Reading&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;celsius&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;reading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Stands in for an OperationCanceledException the pipeline did not cause, so the stage's task&lt;/span&gt;
&lt;span class="c1"&gt;// ends as Faulted rather than Canceled.&lt;/span&gt;
&lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;StageFailedException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;record&lt;/span&gt; &lt;span class="nc"&gt;Reading&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="nc"&gt;Sequence&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;SensorId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;Celsius&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Pipeline stopped: IOException: Database connection lost.
receive: Canceled, parse: Canceled, store: Faulted
received 7,202, rejected 1, parsed 7,100, stored 6,999
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;N/A&lt;/code&gt; line was rejected and the pipeline carried on. When the database "connection" dropped, all three stages stopped, and &lt;code&gt;Task.WhenAll&lt;/code&gt; rethrew the &lt;code&gt;IOException&lt;/code&gt; instead of hanging. A few details in the helper are easy to miss:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Each stage has its own token and uses it for everything it waits on&lt;/strong&gt;: its reads, its writes and, in a real service, its own I/O. Only the stage after it cancels it. When &lt;code&gt;store&lt;/code&gt; failed, it cancelled &lt;code&gt;stopParse&lt;/code&gt;; &lt;code&gt;parse&lt;/code&gt; threw wherever it was waiting and cancelled &lt;code&gt;stopReceive&lt;/code&gt; on its way out, and so on back to the start.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The stages after a failure are never cancelled.&lt;/strong&gt; They read what is left in their channel, and then &lt;code&gt;ReadAllAsync&lt;/code&gt; throws the original exception.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An &lt;code&gt;OperationCanceledException&lt;/code&gt; the pipeline did not cause is a failure.&lt;/strong&gt; An HTTP timeout inside a stage throws one, and left alone it would end the task as &lt;code&gt;Canceled&lt;/code&gt;, so a caller that treats &lt;code&gt;OperationCanceledException&lt;/code&gt; as a normal shutdown would swallow an outage. The &lt;code&gt;when&lt;/code&gt; filter wraps it in a &lt;code&gt;StageFailedException&lt;/code&gt; instead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A stage the pipeline stopped ends as &lt;code&gt;Canceled&lt;/code&gt;, not &lt;code&gt;Faulted&lt;/code&gt;&lt;/strong&gt;, so it adds nothing to what &lt;code&gt;Task.WhenAll&lt;/code&gt; reports, and the exception you get is the cause.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;store&lt;/code&gt; passes &lt;code&gt;complete: null&lt;/code&gt;&lt;/strong&gt; because it is the last stage and has no output channel. And &lt;strong&gt;&lt;code&gt;Task.Run&lt;/code&gt;&lt;/strong&gt; starts each stage on the thread pool, so the three run side by side from the start, instead of the first one running on the caller's thread until its first real wait.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Getting there took me three tries. My first version cancelled one shared token on any failure, so the stages after the failure were cancelled too: with a slow &lt;code&gt;store&lt;/code&gt;, it ended &lt;code&gt;Canceled&lt;/code&gt; before it could see the real exception, because &lt;code&gt;WaitToReadAsync&lt;/code&gt; checks the token before it looks at the channel. My second passed each token only to the writes, and a stage waiting for input never heard about the failure. With a source that sent 20 lines and then went quiet, and &lt;code&gt;store&lt;/code&gt; failing at the 10th, the second version was still running after 10 seconds; this one stopped in 36 ms.&lt;/p&gt;

&lt;p&gt;The downstream half of the helper did not run in that capture, because &lt;code&gt;store&lt;/code&gt; is the last stage. So I ran two more variants, both with &lt;code&gt;store&lt;/code&gt; slowed to 200 µs per reading, as in the load test. When &lt;code&gt;parse&lt;/code&gt; threw an &lt;code&gt;InvalidOperationException&lt;/code&gt; at reading 7,000, &lt;code&gt;store&lt;/code&gt; saved all 6,999 readings &lt;code&gt;parse&lt;/code&gt; had passed on, and then its &lt;code&gt;ReadAllAsync&lt;/code&gt; threw that same exception, not a &lt;code&gt;ChannelClosedException&lt;/code&gt; wrapping it; &lt;code&gt;receive&lt;/code&gt; ended as &lt;code&gt;Canceled&lt;/code&gt;. When &lt;code&gt;receive&lt;/code&gt; itself failed at reading 7,000, all three stages ended &lt;code&gt;Faulted&lt;/code&gt; with its exception, and every reading it had sent was parsed and stored. And when &lt;code&gt;store&lt;/code&gt; threw a &lt;code&gt;TaskCanceledException&lt;/code&gt;, the way an insert that times out does, the pipeline stopped with &lt;code&gt;StageFailedException: The insert timed out.&lt;/code&gt; and &lt;code&gt;store&lt;/code&gt; ended &lt;code&gt;Faulted&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now count what was lost in the capture above: 7,202 lines received, 1 rejected, 6,999 stored. The other 202 never reached the database. They were in the two channels, 100 in each, or in the hands of a stage when it stopped: the reading &lt;code&gt;store&lt;/code&gt; failed on, and the one &lt;code&gt;parse&lt;/code&gt; could not write. (Run it yourself and you may get 201: it depends on whether &lt;code&gt;receive&lt;/code&gt; gets one more line in before the cancellation reaches it.) That is not a bug in the fix. It is what a channel is: it lives in memory, and on a failure or a restart, whatever is in it is gone. When every reading has to survive, the buffer has to be durable and the consumer has to acknowledge each item after storing it, which is a message broker's job.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8krkch9vspee4qk2mynf.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8krkch9vspee4qk2mynf.jpg" alt="Three stations joined by conveyors: station 1 holds a cube with the belt after it packed full, station 2 is marked stopped with a warning sign and a broken gear, and station 3 stands empty under an hourglass" width="799" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The baseline: BlockingCollection
&lt;/h2&gt;

&lt;p&gt;Before channels, the standard producer/consumer queue in .NET was &lt;code&gt;BlockingCollection&amp;lt;T&amp;gt;&lt;/code&gt;, and it still works. The difference is in how its consumers wait. &lt;code&gt;GetConsumingEnumerable()&lt;/code&gt; blocks the thread it runs on until an item arrives, while a channel's &lt;code&gt;ReadAllAsync&lt;/code&gt; awaits and gives the thread back. To measure what that costs, I started 64 consumers on an empty queue, waited a second, then queued one more work item the way Kestrel, ASP.NET Core's web server, queues an incoming request, and timed how long it waited for a thread:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Collections&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Concurrent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Diagnostics&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Channels&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;Consumers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;64&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;threadsAtStart&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetCurrentProcess&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Threads&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"{Environment.ProcessorCount} cores, {Consumers} consumers waiting for work that has not arrived yet"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"{"&lt;/span&gt;&lt;span class="n"&gt;consumers&lt;/span&gt;&lt;span class="s2"&gt;",-32} {"&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;threads&lt;/span&gt;&lt;span class="s2"&gt;",11} {"&lt;/span&gt;&lt;span class="n"&gt;pool&lt;/span&gt; &lt;span class="n"&gt;threads&lt;/span&gt;&lt;span class="s2"&gt;",12} {"&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;queued&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="n"&gt;waited&lt;/span&gt;&lt;span class="s2"&gt;",24}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// A consumer waiting on a channel holds no thread, only a callback to run when an item arrives.&lt;/span&gt;
&lt;span class="nc"&gt;Channel&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateBounded&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1_000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;readers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Enumerable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Consumers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReadAllAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;ReportAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Channel, await foreach"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Writer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Complete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WhenAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;readers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// BlockingCollection on dedicated threads: each consumer blocks a thread of its own.&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;MeasureBlockingCollectionAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"BlockingCollection, LongRunning"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TaskCreationOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;LongRunning&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// BlockingCollection on the thread pool, the way Task.Run starts it in the first example of its docs.&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;MeasureBlockingCollectionAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"BlockingCollection, thread pool"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TaskCreationOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="nc"&gt;MeasureBlockingCollectionAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TaskCreationOptions&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;BlockingCollection&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;boundedCapacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1_000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;consumers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Enumerable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Consumers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Factory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StartNew&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetConsumingEnumerable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nc"&gt;CancellationToken&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TaskScheduler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Default&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;ReportAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CompleteAdding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WhenAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;consumers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="nc"&gt;ReportAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FromSeconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// QueueUserWorkItem uses the pool's global queue, which is where Kestrel puts an incoming request.&lt;/span&gt;
    &lt;span class="nc"&gt;TaskCompletionSource&lt;/span&gt; &lt;span class="n"&gt;started&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;TaskCreationOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RunContinuationsAsynchronously&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Stopwatch&lt;/span&gt; &lt;span class="n"&gt;waited&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Stopwatch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StartNew&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;ThreadPool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;QueueUserWorkItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;started&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SetResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;started&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;newThreads&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetCurrentProcess&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Threads&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Count&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;threadsAtStart&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"{label,-32} {newThreads,11} {ThreadPool.ThreadCount,12} {waited.Elapsed.TotalMilliseconds,21:N1} ms"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;8 cores, 64 consumers waiting for work that has not arrived yet
consumers                        new threads pool threads  a queued request waited
Channel, await foreach                    10            8                   8.8 ms
BlockingCollection, LongRunning           75            9                   4.8 ms
BlockingCollection, thread pool           65           65              43,093.5 ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;64 consumers awaiting a channel cost no threads.&lt;/strong&gt; The thread pool stayed at 8 threads, one per core, and the queued work item started in under 10 ms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;BlockingCollection&lt;/code&gt; on dedicated threads&lt;/strong&gt;, with &lt;code&gt;TaskCreationOptions.LongRunning&lt;/code&gt;, costs one thread per consumer: 64 threads doing nothing, each with its own stack. They are not the pool's threads, so the queued work item still started in under 10 ms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;BlockingCollection&lt;/code&gt; on the thread pool&lt;/strong&gt; is where &lt;code&gt;Task.Run&lt;/code&gt; puts it, and &lt;code&gt;Task.Run&lt;/code&gt; is how the first example in &lt;a href="https://learn.microsoft.com/en-us/dotnet/standard/collections/thread-safe/blockingcollection-overview" rel="noopener noreferrer"&gt;its own docs&lt;/a&gt; starts the consumer. Each waiting consumer holds a pool thread, and the pool cannot tell a blocked thread from a busy one, so it adds threads slowly. Microsoft's &lt;a href="https://learn.microsoft.com/en-us/dotnet/core/diagnostics/debug-threadpool-starvation" rel="noopener noreferrer"&gt;guide to thread pool starvation&lt;/a&gt; describes it: past a first quick jump, "further threads are added 1-2 per second". The queued work item waited 43.1 seconds in this run, and between 37.1 and 40.0 in three others. In ASP.NET Core, that work item is a request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;BlockingCollection&lt;/code&gt; is not broken; it is synchronous. In a console tool or a service that runs on its own threads, it is fine. In async code, a consumer waiting on it blocks a thread the rest of the app needs, and a channel does the same job without one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvmh0p26qhgqq8uuli2l0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvmh0p26qhgqq8uuli2l0.jpg" alt="On the left, thread spools tied to sleeping boxes while a long row of envelopes waits in front of them; on the right, tickets pinned on a board and free spools, one of them already taking an envelope" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use a channel, and when not
&lt;/h2&gt;

&lt;p&gt;Use one for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Producer and consumer in the same process&lt;/strong&gt;, such as a &lt;code&gt;BackgroundService&lt;/code&gt; in ASP.NET Core reading jobs that endpoints write to a bounded channel.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pipelines&lt;/strong&gt;, where each stage runs at its own pace and a bounded channel between two stages keeps a fast one from flooding a slow one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Absorbing bursts&lt;/strong&gt;, with a capacity sized to the latency you can accept: capacity × time per item.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use something else when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Items must survive a crash or a deploy.&lt;/strong&gt; A channel is memory. Use a durable queue, as in &lt;a href="https://dev.to/jgomezdev/rabbitmq-from-fundamentals-to-production-part-2-building-a-scalable-service-4nk2"&gt;RabbitMQ from Fundamentals to Production, Part 2: Building a Scalable Service&lt;/a&gt;, or a database table, and acknowledge each item after the work is done.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The producer and the consumer are different processes.&lt;/strong&gt; Same answer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You need retries, schedules or a dashboard of jobs.&lt;/strong&gt; That is a job scheduler such as Hangfire or Quartz.NET, not a queue.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You only need to process a known list in parallel.&lt;/strong&gt; &lt;code&gt;Parallel.ForEachAsync&lt;/code&gt; with &lt;code&gt;MaxDegreeOfParallelism&lt;/code&gt; is shorter and leaves nothing to complete or drain.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;In a drop mode, a write that loses its item still returns &lt;code&gt;true&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;itemDropped&lt;/code&gt; is the only signal: count it and export it as a metric.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;DropNewest&lt;/code&gt; drops the newest item already in the channel, not the one being written.&lt;/strong&gt; Of the three drop modes, only &lt;code&gt;DropOldest&lt;/code&gt; kept the consumer on fresh data, with a median wait of 20 ms against about 200.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Wait&lt;/code&gt; never loses an item and makes the producer pay&lt;/strong&gt;: capacity × time per item is the latency you choose. And &lt;code&gt;TryWrite&lt;/code&gt; never waits, even in &lt;code&gt;Wait&lt;/code&gt; mode.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A stage that throws stalls the whole pipeline without a word.&lt;/strong&gt; Complete its output with the exception and cancel the stage before it, wherever it is waiting; never cancel the stages after it. &lt;code&gt;finally { Complete(); }&lt;/code&gt; alone leaves the hang and makes the next stage report success on half the data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;BlockingCollection&lt;/code&gt; holds a thread for every consumer that waits.&lt;/strong&gt; On the thread pool, 64 of them kept an unrelated work item waiting for between 37 and 43 seconds.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>concurrency</category>
      <category>performance</category>
    </item>
    <item>
      <title>Rust is not faster by default: how my .NET client got 33x ahead of the official Rust SDK</title>
      <dc:creator>Daniel</dc:creator>
      <pubDate>Tue, 17 Nov 2026 13:59:25 +0000</pubDate>
      <link>https://dev.to/axitordev/rust-is-not-faster-by-default-how-my-net-client-got-33x-ahead-of-the-official-rust-sdk-360f</link>
      <guid>https://dev.to/axitordev/rust-is-not-faster-by-default-how-my-net-client-got-33x-ahead-of-the-official-rust-sdk-360f</guid>
      <description>&lt;p&gt;I open-sourced a Binance client for .NET 10. It's up to &lt;strong&gt;33x faster per message&lt;/strong&gt; than the official Binance Rust SDK, has &lt;strong&gt;43x better p99.9 latency&lt;/strong&gt;, and allocates &lt;strong&gt;zero bytes&lt;/strong&gt; on the hot path.&lt;/p&gt;

&lt;p&gt;Whenever I mention this, someone tells me Rust is fast by default and .NET is the managed, garbage-collected compromise. I've been building .NET systems for 25 years and I've never believed that. So I ran a benchmark that's hard to argue with.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Axitor" rel="noopener noreferrer"&gt;
        Axitor
      &lt;/a&gt; / &lt;a href="https://github.com/Axitor/Trading.Gateway" rel="noopener noreferrer"&gt;
        Trading.Gateway
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Binance client for .NET 10, faster than every major Binance client in .NET and Rust. Zero allocations on the hot path, resilience built in, Native AOT ready. REST, WebSocket API, JSON and SBE streams, user data and local order books.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Axitor.Trading.Gateway&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Faster than every major Binance client. In .NET, and in Rust.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;A Binance gateway for .NET 10, built for trading bots where the slow message, the dead socket and the ban cost real money. Zero allocations on the hot path. Resilience in the core. Native AOT from day one.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/Axitor/Trading.Gateway/actions/workflows/ci.yml" rel="noopener noreferrer"&gt;&lt;img src="https://github.com/Axitor/Trading.Gateway/actions/workflows/ci.yml/badge.svg" alt="CI"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/7434d72ea2c9e35186c22a992fa4db2629024449957bd17244cb67031f2901dd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2e4e45542d31302d353132424434"&gt;&lt;img src="https://camo.githubusercontent.com/7434d72ea2c9e35186c22a992fa4db2629024449957bd17244cb67031f2901dd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2e4e45542d31302d353132424434" alt=".NET 10"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/d8ec2845301654650919199f1fa41d0d177c78ab9508ddb53df109e56ca26858/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4e6174697665253230414f542d72656164792d326561343466"&gt;&lt;img src="https://camo.githubusercontent.com/d8ec2845301654650919199f1fa41d0d177c78ab9508ddb53df109e56ca26858/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4e6174697665253230414f542d72656164792d326561343466" alt="Native AOT"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/09a1a3f2e5dc3283da5060021e3ebc76f2e73f741c7134d019f57196cd05dcc0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f686f74253230706174682d7a65726f253230616c6c6f632d326561343466"&gt;&lt;img src="https://camo.githubusercontent.com/09a1a3f2e5dc3283da5060021e3ebc76f2e73f741c7134d019f57196cd05dcc0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f686f74253230706174682d7a65726f253230616c6c6f632d326561343466" alt="Hot path"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/25f22433216f57b7e8ab05cd38038bf35055fcebc89a3139af90122b9342a7b0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c7565"&gt;&lt;img src="https://camo.githubusercontent.com/25f22433216f57b7e8ab05cd38038bf35055fcebc89a3139af90122b9342a7b0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c7565" alt="License"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;In numbers&lt;/h2&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;33x lower cost per message&lt;/strong&gt; than the official Binance Rust SDK. &lt;strong&gt;15x&lt;/strong&gt; lower than Binance.Net.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;1.14 million messages per second&lt;/strong&gt; on a single connection, on a desktop CPU from 2014. Up to &lt;strong&gt;17x&lt;/strong&gt; the throughput of the Rust SDK, up to &lt;strong&gt;8.6x&lt;/strong&gt; Binance.Net, even in its high-performance mode.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;43x better p99.9 latency&lt;/strong&gt; than the Rust SDK, &lt;strong&gt;16x&lt;/strong&gt; better than Binance.Net, on the busiest stream.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;0 bytes, 0 GC&lt;/strong&gt; on the stream hot path. Binance.Net makes up to 285 collections per run, with GC pauses up to 72 ms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;1,500 candles in 3 KB.&lt;/strong&gt; Binance.Net needs 1.76 MB, the…&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Axitor/Trading.Gateway" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  How I tested
&lt;/h2&gt;

&lt;p&gt;I didn't compare pieces of my code to pieces of someone else's. I ran whole clients through their public APIs, the same way a trading bot would use them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Axitor.Trading.Gateway&lt;/strong&gt;, my client, .NET 10, JIT and Native AOT builds&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Binance.Net 13.8.0&lt;/strong&gt;, the standard .NET client, in its default mode and its high-performance mode, with its rate limiters turned off&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;binance-sdk 77.1.0&lt;/strong&gt;, the official Binance Rust connector&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;nautilus-binance 0.66.0&lt;/strong&gt;, NautilusTrader's Binance adapter, also in Rust&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every client reads the same recorded Binance mainnet traffic (about 640k book tickers and 98k depth updates across 20 symbols) from the same local exchange stub on the same machine. As a baseline I added a raw socket loop that just reads messages and throws them away.&lt;/p&gt;

&lt;p&gt;I look at two numbers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Client cost per message.&lt;/strong&gt; How much time a client adds on top of that raw socket read. The transport is the same for everyone, so this shows what each client's own code costs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tail latency at live pace.&lt;/strong&gt; Frames are replayed with their original timing, and I measure from send to handler.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The box is an Intel Core i7-5820K from 2014 on Windows 10, with .NET 10.0.14 and BenchmarkDotNet 0.15.8. Old hardware makes waste easy to see.&lt;/p&gt;

&lt;p&gt;Full method, all tables and the fairness rules are in &lt;a href="https://github.com/Axitor/Trading.Gateway/blob/main/docs/adr/ADR-0018-Benchmarks-that-measure-the-real-thing.md" rel="noopener noreferrer"&gt;ADR-0018&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The numbers
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Axitor&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;Binance.Net&lt;/th&gt;
&lt;th&gt;binance-sdk (Rust)&lt;/th&gt;
&lt;th&gt;Nautilus (Rust)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Cost per depth update&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0.97 µs&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;15.0 µs&lt;/td&gt;
&lt;td&gt;32.1 µs&lt;/td&gt;
&lt;td&gt;20.3 µs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Book ticker, one connection&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1.14M msg/s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;291k&lt;/td&gt;
&lt;td&gt;129k&lt;/td&gt;
&lt;td&gt;181k&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Depth, one connection&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;484k msg/s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;62.2k&lt;/td&gt;
&lt;td&gt;30.1k&lt;/td&gt;
&lt;td&gt;46.7k&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Book ticker p99.9 at live pace&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;237 µs&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;3,911 µs&lt;/td&gt;
&lt;td&gt;10,223 µs&lt;/td&gt;
&lt;td&gt;7,042 µs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Memory per book ticker&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0 B&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;1,056 B&lt;/td&gt;
&lt;td&gt;3,584 B&lt;/td&gt;
&lt;td&gt;1,751 B&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1,500 candles over REST&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;638 µs, 3 KB&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;5.49 ms, 1.76 MB&lt;/td&gt;
&lt;td&gt;8.18 ms, 3.97 MB&lt;/td&gt;
&lt;td&gt;3.66 ms, 2.91 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Against the official Rust SDK that's &lt;strong&gt;33x faster&lt;/strong&gt; per message, up to &lt;strong&gt;17x faster&lt;/strong&gt; throughput, &lt;strong&gt;43x better&lt;/strong&gt; at p99.9, and &lt;strong&gt;1,270x better&lt;/strong&gt; on memory for 1,500 candles: 3 KB against 3.97 MB.&lt;/p&gt;

&lt;p&gt;Against NautilusTrader's adapter it's &lt;strong&gt;21x&lt;/strong&gt;, &lt;strong&gt;11x&lt;/strong&gt; and &lt;strong&gt;30x&lt;/strong&gt;. Against Binance.Net it's &lt;strong&gt;15x&lt;/strong&gt; per message and up to &lt;strong&gt;8.6x&lt;/strong&gt; on throughput, even with Binance.Net in its high-performance mode.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the Rust SDK loses time
&lt;/h2&gt;

&lt;p&gt;Rust doesn't have a garbage collector, but allocating still isn't free.&lt;/p&gt;

&lt;p&gt;binance-sdk is generated from Binance's OpenAPI spec. For every frame it copies the bytes into a string, parses that into a JSON tree, clones the tree twice and turns every number into its own heap string. One book ticker message ends up with &lt;strong&gt;69 heap allocations&lt;/strong&gt;. You won't see GC pauses, because there is no GC. You pay with time instead, on every &lt;code&gt;malloc&lt;/code&gt; and every &lt;code&gt;free&lt;/code&gt;, inside every message.&lt;/p&gt;

&lt;p&gt;NautilusTrader's adapter does better at 40 allocations per book ticker, but it still copies every frame and sends it through unbounded queues.&lt;/p&gt;

&lt;p&gt;Binance.Net, meanwhile, is the .NET stereotype in action. It creates an object for every message: about 1 KB per book ticker and 6 to 10 KB per depth update. Under load that turns into up to &lt;strong&gt;285 garbage collections per run&lt;/strong&gt;, Gen1 and Gen2 included, with &lt;strong&gt;pauses up to 72 ms&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;None of that comes from the runtime. It comes from the design. Here's what I did differently.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I did differently
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Parse in place, into flat structs
&lt;/h3&gt;

&lt;p&gt;Messages go straight from the UTF-8 bytes in the socket buffer into a flat struct with public fields. There's no JSON tree, no strings and no reflection anywhere. I wrote the readers by hand, and prices go through an exact fast-path decimal parser (Clinger's fast path). Even the symbol is packed into one &lt;code&gt;UInt128&lt;/code&gt;, so &lt;code&gt;BTCUSDT&lt;/code&gt; never becomes a string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;BookTickerModel&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Symbol&lt;/span&gt; &lt;span class="nc"&gt;Symbol&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="nc"&gt;UpdateId&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="nc"&gt;EventTime&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="nc"&gt;TransactionTime&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;BidPrice&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;BidQuantity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;AskPrice&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;AskQuantity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's a plain struct with public fields, so there are no property getters or defensive copies, and the GC has nothing to track.&lt;/p&gt;

&lt;h3&gt;
  
  
  No virtual calls on dispatch
&lt;/h3&gt;

&lt;p&gt;Your handler is a &lt;code&gt;readonly struct&lt;/code&gt;, and so is the dispatcher. It's generic over both the parser and the handler:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;internal&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;BinanceDepthDispatcher&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;TParser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;THandler&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;IWsStreamDispatcher&lt;/span&gt;
    &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="nc"&gt;TParser&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;IBinanceDepthParser&lt;/span&gt;
    &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="nc"&gt;THandler&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;IBinanceDepthHandler&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nc"&gt;THandler&lt;/span&gt; &lt;span class="n"&gt;_handler&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;_lastUpdateIds&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nc"&gt;DepthLevel&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;_bids&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nc"&gt;DepthLevel&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;_asks&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;MethodImpl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MethodImplOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AggressiveInlining&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;WsDispatchResult&lt;/span&gt; &lt;span class="nc"&gt;Dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;subscription&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ReadOnlySpan&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="nc"&gt;DepthLevel&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;bids&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;_bids&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;subscription&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="nc"&gt;DepthLevel&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;asks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;_asks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;subscription&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nc"&gt;TParser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TryParse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="nc"&gt;DepthUpdateHeader&lt;/span&gt; &lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;bids&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;bidCount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;asks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;askCount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;WsDispatchResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Unreadable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;lastUpdateId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;_lastUpdateIds&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;subscription&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FinalUpdateId&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;lastUpdateId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;WsDispatchResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Handled&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;lastUpdateId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FinalUpdateId&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;_handler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OnData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;subscription&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bids&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AsSpan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bidCount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;asks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AsSpan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;askCount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;WsDispatchResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Handled&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the type arguments are structs, .NET doesn't share generic code between them. The JIT (or the AOT compiler, ahead of time) builds a separate copy of this method for your exact parser and handler. In that copy &lt;code&gt;OnData&lt;/code&gt; is a direct call to a known method, and if it's small it gets inlined right into the receive loop. The parser is a &lt;code&gt;static abstract&lt;/code&gt; interface member, so there's no parser object either, just a static call resolved at compile time.&lt;/p&gt;

&lt;p&gt;The interfaces are there for the compiler to check. At runtime nothing goes through them: no events, no delegates, no virtual calls.&lt;/p&gt;

&lt;h3&gt;
  
  
  Zero allocations per message
&lt;/h3&gt;

&lt;p&gt;Level buffers are created once per subscription and reused. The order book uses a seqlock, so any thread can read the best price or the whole book without taking a lock and without slowing down the receive loop. Each stream message costs &lt;strong&gt;0 bytes&lt;/strong&gt;, and the GC simply never runs on the hot path.&lt;/p&gt;

&lt;h3&gt;
  
  
  Native AOT from the start
&lt;/h3&gt;

&lt;p&gt;The build enforces trimming and AOT compatibility, so reflection is a compile error instead of a surprise in production. The AOT build actually has the best p50 and p99 on every stream I measured: 84 µs and 198 µs on book ticker at live market pace.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I care most about the tail
&lt;/h2&gt;

&lt;p&gt;At the median every client looks okay. The network and the kernel cost everyone the same, so the gap there is just 1.2x to 2x.&lt;/p&gt;

&lt;p&gt;Bursts are a different story. When the market moves fast, messages come in clumps, and your tail latency is roughly the time per message multiplied by the size of the burst. If a client handles each message 10x faster, it clears a burst 10x faster. That's why at p99.9 on the busiest stream the gap grows to &lt;strong&gt;16x to 43x&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Trading bots rarely lose money on the average message. They lose it on the slow one, and the slow one tends to show up right when the price is moving.&lt;/p&gt;

&lt;h2&gt;
  
  
  So is Rust slow?
&lt;/h2&gt;

&lt;p&gt;No, and that's not what I'm saying. Rust is a great language. What I'm saying is that the language doesn't decide how fast your code is. Your design does.&lt;/p&gt;

&lt;p&gt;A Rust client that allocates 69 times per message will lose to a C# client that allocates nothing. Modern .NET gives you everything you need for that kind of code: structs, spans, generic specialization, &lt;code&gt;static abstract&lt;/code&gt; members, &lt;code&gt;InlineArray&lt;/code&gt;, &lt;code&gt;SearchValues&lt;/code&gt; and Native AOT. Write C# this way and you don't have to settle for "close to Rust". In this benchmark it beat both Rust clients by more than an order of magnitude.&lt;/p&gt;

&lt;h2&gt;
  
  
  Speed is only half of it
&lt;/h2&gt;

&lt;p&gt;The other half is surviving the failures no benchmark will show you. The gateway has a watchdog that catches sockets that look alive but carry no data, one network gate shared by REST, the WebSocket API and reconnects, and make-before-break connection rotation. On top of that there's a rate limiter that can't get your IP banned, and orders can't be sent twice by accident. I wrote up every one of these decisions as an ADR: the problem, what I decided, what it costs and what I rejected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Repo: &lt;a href="https://github.com/Axitor/Trading.Gateway" rel="noopener noreferrer"&gt;github.com/Axitor/Trading.Gateway&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Why I built it: &lt;a href="https://github.com/Axitor/Trading.Gateway/blob/main/docs/adr/ADR-0001-Why-another-Binance-client.md" rel="noopener noreferrer"&gt;ADR-0001&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Benchmark method and all tables: &lt;a href="https://github.com/Axitor/Trading.Gateway/blob/main/docs/adr/ADR-0018-Benchmarks-that-measure-the-real-thing.md" rel="noopener noreferrer"&gt;ADR-0018&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The benchmarks are reproducible. Record your own mainnet data with the recorder in &lt;code&gt;bench/tools&lt;/code&gt;, build the Rust competitors, and run one script.&lt;/p&gt;

&lt;h3&gt;
  
  
  ⭐ If you liked this, star the repo
&lt;/h3&gt;

&lt;p&gt;Seriously, it's the best way to help. Stars are how other .NET and trading folks find the project, and they tell me to keep going. Next up: the rest of the Binance API, FIX, and more exchanges on the same core.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;&lt;a href="https://github.com/Axitor/Trading.Gateway" rel="noopener noreferrer"&gt;Star Axitor.Trading.Gateway on GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;I'm Daniel Lebedev, a Principal .NET Architect with 25+ years in low-latency and high-load systems. I make .NET systems faster and more reliable, and I'm open to remote roles and contracts. &lt;a href="https://www.linkedin.com/in/axitor/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>rust</category>
      <category>performance</category>
    </item>
    <item>
      <title>NuGet Manager for VS Code: manage your .NET packages without leaving the editor</title>
      <dc:creator>Bruno Sales</dc:creator>
      <pubDate>Tue, 17 Nov 2026 13:49:33 +0000</pubDate>
      <link>https://dev.to/baliestri/nuget-manager-for-vs-code-manage-your-net-packages-without-leaving-the-editor-511f</link>
      <guid>https://dev.to/baliestri/nuget-manager-for-vs-code-manage-your-net-packages-without-leaving-the-editor-511f</guid>
      <description>&lt;p&gt;If you work on a .NET solution in VS Code, you have probably switched to a terminal or a browser to check which packages have updates, or to install one in a project you did not expect. I got tired of that, so I built &lt;strong&gt;NuGet Manager for VS Code&lt;/strong&gt;: a NuGet window inside the editor.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5j46teas6ynipb76bk6n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5j46teas6ynipb76bk6n.png" alt="The Packages tab in the editor" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Its layout follows the NuGet window of &lt;strong&gt;JetBrains Rider&lt;/strong&gt;, which I use as the reference for how the view should present things. The extension is not affiliated with JetBrains.&lt;/p&gt;

&lt;p&gt;It is available on both stores:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Visual Studio Marketplace:&lt;/strong&gt; &lt;a href="https://marketplace.visualstudio.com/items?itemName=baliestri.nuget-code" rel="noopener noreferrer"&gt;https://marketplace.visualstudio.com/items?itemName=baliestri.nuget-code&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Open VSX:&lt;/strong&gt; &lt;a href="https://open-vsx.org/extension/baliestri/nuget-code" rel="noopener noreferrer"&gt;https://open-vsx.org/extension/baliestri/nuget-code&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The source is on GitHub: &lt;a href="https://github.com/baliestri/nuget-code" rel="noopener noreferrer"&gt;https://github.com/baliestri/nuget-code&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What it does
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Installed packages&lt;/strong&gt; for the whole solution or for one project, and the packages with a newer version. Tick several and update them together.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transitive packages and known vulnerabilities.&lt;/strong&gt; The packages that come with the ones you reference are listed too, and any package with a known vulnerability is marked.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Discover&lt;/strong&gt; searches your feeds, with or without prereleases.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm1pdbqvjl90c497k941t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm1pdbqvjl90c497k941t.png" alt="Searching the feeds in Discover" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sources.&lt;/strong&gt; Every &lt;code&gt;NuGet.config&lt;/code&gt; NuGet reads, with the feeds of each. Add, edit, enable, disable and remove them. Private feed credentials go into the editor's secret storage, never into a &lt;code&gt;NuGet.config&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Folders.&lt;/strong&gt; See how much disk the NuGet caches take, and clear the ones you select.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Log.&lt;/strong&gt; What NuGet and the backend are doing, as it happens, coloured by level and filtered as you like.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Package Manager Console.&lt;/strong&gt; A PowerShell terminal with &lt;code&gt;Get-Package&lt;/code&gt;, &lt;code&gt;Install-Package&lt;/code&gt;, &lt;code&gt;Update-Package&lt;/code&gt; and the other cmdlets you know from Visual Studio.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fshsx1r4leqzu700wpada.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fshsx1r4leqzu700wpada.png" alt="The Package Manager Console in the editor" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiwqxovhrm9dmbup9l4dy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiwqxovhrm9dmbup9l4dy.png" alt="Choosing the default project in the console" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Versions are changed where they are declared: in the project, in &lt;code&gt;Directory.Packages.props&lt;/code&gt; with central package management, in a &lt;code&gt;VersionOverride&lt;/code&gt;, or in a property.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;The view is a webview, and the work is done by a native backend built on &lt;a href="https://github.com/NuGet/NuGet.Client" rel="noopener noreferrer"&gt;NuGet.Client&lt;/a&gt;. The extension does not parse the output of &lt;code&gt;dotnet list package&lt;/code&gt;. The backend reads your solution, your &lt;code&gt;NuGet.config&lt;/code&gt; files and your feeds the way NuGet itself does, so the answers are the ones &lt;code&gt;dotnet&lt;/code&gt; would give.&lt;/p&gt;

&lt;p&gt;Restore can use three engines, set in &lt;code&gt;nuget.restore.engine&lt;/code&gt;: &lt;code&gt;embedded&lt;/code&gt; (the default, inside the backend), &lt;code&gt;msbuild&lt;/code&gt;, or &lt;code&gt;console&lt;/code&gt; (&lt;code&gt;dotnet restore&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Visual Studio Code 1.100 or newer, or an editor built from it, such as VSCodium.&lt;/li&gt;
&lt;li&gt;A .NET SDK. Without one, the extension can still list sources and search packages, but cannot open a solution.&lt;/li&gt;
&lt;li&gt;A trusted workspace: reading projects runs MSBuild, which executes code from the repository.&lt;/li&gt;
&lt;li&gt;PowerShell 7.6 or newer, only for the Package Manager Console.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It runs on Windows, Linux (glibc and musl) and macOS, on x64 and arm64, and also in Remote SSH, WSL and containers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;Open a folder with a &lt;code&gt;.sln&lt;/code&gt;, &lt;code&gt;.slnx&lt;/code&gt; or &lt;code&gt;.csproj&lt;/code&gt;, then open the &lt;strong&gt;NuGet&lt;/strong&gt; tab of the panel, or run &lt;strong&gt;NuGet: Open&lt;/strong&gt; from the command palette.&lt;/p&gt;

&lt;p&gt;Feedback and bug reports are welcome on the &lt;a href="https://github.com/baliestri/nuget-code/issues" rel="noopener noreferrer"&gt;issue tracker&lt;/a&gt;. If the extension saves you a few trips to the browser, a rating on your store of choice helps others find it.&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>dotnet</category>
      <category>nuget</category>
      <category>programming</category>
    </item>
    <item>
      <title>Data types, numbers and type conversion (C# Language)</title>
      <dc:creator>DIVAKAR UPADHYAY</dc:creator>
      <pubDate>Tue, 17 Nov 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/divakarupadhyay/data-types-numbers-and-type-conversion-c-language-e65</link>
      <guid>https://dev.to/divakarupadhyay/data-types-numbers-and-type-conversion-c-language-e65</guid>
      <description>&lt;p&gt;&lt;strong&gt;👉 &lt;a href="https://devladder.pages.dev/courses/csharp/lessons/data-types-numbers-and-type-conversion" rel="noopener noreferrer"&gt;Full lesson with practice questions on DevLadder&lt;/a&gt;&lt;/strong&gt; (free, lesson 3 of 38 in the &lt;a href="https://devladder.pages.dev/courses/csharp" rel="noopener noreferrer"&gt;C# Language: Basics to Advanced&lt;/a&gt; course)&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;C# keyword&lt;/th&gt;
&lt;th&gt;.NET type&lt;/th&gt;
&lt;th&gt;Size&lt;/th&gt;
&lt;th&gt;Range / precision&lt;/th&gt;
&lt;th&gt;Literal&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;byte&lt;/code&gt; / &lt;code&gt;sbyte&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Byte&lt;/code&gt; / &lt;code&gt;SByte&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;1 byte&lt;/td&gt;
&lt;td&gt;0–255 / −128–127&lt;/td&gt;
&lt;td&gt;&lt;code&gt;255&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;short&lt;/code&gt; / &lt;code&gt;ushort&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Int16&lt;/code&gt; / &lt;code&gt;UInt16&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;2 bytes&lt;/td&gt;
&lt;td&gt;±32,767 / 0–65,535&lt;/td&gt;
&lt;td&gt;&lt;code&gt;100&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;int&lt;/code&gt; / &lt;code&gt;uint&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Int32&lt;/code&gt; / &lt;code&gt;UInt32&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;4 bytes&lt;/td&gt;
&lt;td&gt;±2.1 billion&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;42&lt;/code&gt;, &lt;code&gt;42u&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;long&lt;/code&gt; / &lt;code&gt;ulong&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Int64&lt;/code&gt; / &lt;code&gt;UInt64&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;8 bytes&lt;/td&gt;
&lt;td&gt;±9.2 × 10¹⁸&lt;/td&gt;
&lt;td&gt;&lt;code&gt;42L&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;float&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Single&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;4 bytes&lt;/td&gt;
&lt;td&gt;~6–9 digits, binary floating point&lt;/td&gt;
&lt;td&gt;&lt;code&gt;1.5f&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;double&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Double&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;8 bytes&lt;/td&gt;
&lt;td&gt;~15–17 digits, binary floating point (default for decimals)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;1.5&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;decimal&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Decimal&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;16 bytes&lt;/td&gt;
&lt;td&gt;28–29 digits, base-10: &lt;strong&gt;use for money&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;1.5m&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;char&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Char&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2 bytes&lt;/td&gt;
&lt;td&gt;One UTF-16 code unit&lt;/td&gt;
&lt;td&gt;&lt;code&gt;'A'&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;bool&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Boolean&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1 byte&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;true&lt;/code&gt; / &lt;code&gt;false&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;true&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;String&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;reference&lt;/td&gt;
&lt;td&gt;Immutable text&lt;/td&gt;
&lt;td&gt;&lt;code&gt;"text"&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;object&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Object&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;reference&lt;/td&gt;
&lt;td&gt;Base of every type&lt;/td&gt;
&lt;td&gt;:&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;       &lt;span class="c1"&gt;// False: binary floating point can't store 0.1 exactly&lt;/span&gt;
&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.1m&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.2m&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mf"&gt;0.3m&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;// True: decimal is exact for base-10 values&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;big&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1_000_000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                        &lt;span class="c1"&gt;// digit separators&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;hex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0xFF&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mb"&gt;0b1010&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Integer overflow wraps silently by default...&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;MaxValue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;wrapped&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;unchecked&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;           &lt;span class="c1"&gt;// -2147483648&lt;/span&gt;
&lt;span class="c1"&gt;// ...unless you ask for checking&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;boom&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;checked&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;OverflowException&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Overflow!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;// 3: integer division truncates&lt;/span&gt;
&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;2.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// 3.5&lt;/span&gt;
&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;// 1: remainder&lt;/span&gt;
&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;2.5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                              &lt;span class="c1"&gt;// 2: banker's rounding (to even) by default&lt;/span&gt;
&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;2.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;MidpointRounding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AwayFromZero&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Type conversion:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Kind&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Implicit (widening)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;long l = intValue; double d = intValue;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Safe, no data loss, no syntax needed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Explicit cast (narrowing)&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;int i = (int)3.99;&lt;/code&gt; → &lt;code&gt;3&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;May lose data; truncates decimals&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;Convert&lt;/code&gt; class&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Convert.ToInt32("42")&lt;/code&gt;, &lt;code&gt;Convert.ToInt32(3.5)&lt;/code&gt; → &lt;code&gt;4&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Rounds to even; &lt;code&gt;null&lt;/code&gt; → 0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Parse&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;int.Parse("42")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Throws &lt;code&gt;FormatException&lt;/code&gt; on bad input&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;TryParse&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;int.TryParse(input, out var n)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns &lt;code&gt;false&lt;/code&gt; instead of throwing: &lt;strong&gt;use for user input&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;as&lt;/code&gt; / &lt;code&gt;is&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;obj as string&lt;/code&gt;, &lt;code&gt;obj is int n&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Reference/pattern conversions without exceptions&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TryParse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReadLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;qty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;qty&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"Ordering {qty}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Please enter a positive number"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"1,234.50"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;NumberStyles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;CultureInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;InvariantCulture&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// culture decides what , and . mean&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Interview tip:&lt;/strong&gt; "Why decimal for money?", &lt;code&gt;double&lt;/code&gt; is binary and can't represent 0.1 exactly, so sums drift (&lt;code&gt;0.1 + 0.2 != 0.3&lt;/code&gt;). &lt;code&gt;decimal&lt;/code&gt; stores base-10 digits exactly, at the cost of speed and memory.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Interview questions on C# Language
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is the difference between a value type and a reference type?
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;value type&lt;/strong&gt; variable holds the data itself (&lt;code&gt;int&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;decimal&lt;/code&gt;, &lt;code&gt;DateTime&lt;/code&gt;, any &lt;code&gt;struct&lt;/code&gt;/&lt;code&gt;enum&lt;/code&gt;). Assigning it copies the value. A reference type variable holds a reference to an object on the managed heap (&lt;code&gt;class&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, arrays, delegates, &lt;code&gt;record&lt;/code&gt;). Assigning it copies the reference, so two variables can point to the same object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// a.Count == 1: same object&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                       &lt;span class="c1"&gt;// x is still 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Value types are stored inline (stack for locals, inside the parent object for fields); reference-type objects always live on the heap and are cleaned up by the GC.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between &lt;code&gt;string&lt;/code&gt; and &lt;code&gt;StringBuilder&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;string&lt;/code&gt; is &lt;strong&gt;immutable&lt;/strong&gt;: every concatenation creates a new string object, so building a string in a loop causes many allocations (O(n²) copying). &lt;code&gt;StringBuilder&lt;/code&gt; keeps a mutable buffer and appends in place; call &lt;code&gt;ToString()&lt;/code&gt; once at the end. Use &lt;code&gt;StringBuilder&lt;/code&gt; for loops or many appends, plain strings/interpolation for a handful of pieces.&lt;/p&gt;

&lt;h3&gt;
  
  
  Explain &lt;code&gt;const&lt;/code&gt; vs &lt;code&gt;readonly&lt;/code&gt; vs &lt;code&gt;static readonly&lt;/code&gt;.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;const&lt;/code&gt;: compile-time constant, implicitly static, only primitives/strings; the value is &lt;strong&gt;baked into callers&lt;/strong&gt; at compile time.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;readonly&lt;/code&gt;: instance field assigned at declaration or in a constructor; can differ per object.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;static readonly&lt;/code&gt;: one value per type, computed at runtime (e.g. &lt;code&gt;static readonly HttpClient Client = new()&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Gotcha: if library A has &lt;code&gt;public const int Max = 10&lt;/code&gt; and app B uses it, changing it to 20 in A does nothing in B until B is recompiled. Use &lt;code&gt;static readonly&lt;/code&gt; for values that may change.&lt;/p&gt;




&lt;p&gt;Read the &lt;a href="https://devladder.pages.dev/courses/csharp/lessons/data-types-numbers-and-type-conversion" rel="noopener noreferrer"&gt;full lesson with progress tracking&lt;/a&gt; and the rest of the course on &lt;strong&gt;DevLadder&lt;/strong&gt;: free step-by-step tutorials and interview questions for developers.&lt;/p&gt;

&lt;p&gt;Next in the course: &lt;a href="https://devladder.pages.dev/courses/csharp/lessons/value-types-vs-reference-types" rel="noopener noreferrer"&gt;Value types vs reference types&lt;/a&gt; →&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>beginners</category>
      <category>interview</category>
    </item>
    <item>
      <title>Staying hands-on while leading delivery</title>
      <dc:creator>Anas Amin</dc:creator>
      <pubDate>Tue, 17 Nov 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/anasamin22311/staying-hands-on-while-leading-delivery-bd2</link>
      <guid>https://dev.to/anasamin22311/staying-hands-on-while-leading-delivery-bd2</guid>
      <description>&lt;p&gt;&lt;em&gt;Hands-on leadership does not mean taking every difficult ticket. It means staying close enough to the code and production path to make sound decisions, while giving the team clear ownership of the work. The examples come from Zotic, Amlaak, Happy Ticket, Project Pavilion and Alreef.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Leadership and coding are one feedback loop
&lt;/h2&gt;

&lt;p&gt;Architecture, planning, review, and deployment are often treated as separate responsibilities. In practice, each one corrects the others. A deployment exposes operational constraints. Those constraints change an architecture decision. The decision changes how work should be sliced. Code review shows whether the slice was clear enough.&lt;/p&gt;

&lt;p&gt;A lead who never touches that loop can make decisions based on diagrams that no longer match the system. A lead who keeps all hard implementation work has the opposite problem: the team waits for one person and never gains ownership.&lt;/p&gt;

&lt;h2&gt;
  
  
  Write down the decision before the task list
&lt;/h2&gt;

&lt;p&gt;A short decision note is usually enough. State the problem, the constraints, the chosen approach, the alternatives that were considered, and what would cause the choice to be revisited. The purpose is not documentation volume. It is to stop the same argument from restarting inside every pull request.&lt;/p&gt;

&lt;p&gt;Keep the decision close to the codebase or delivery workspace. Link it from the work that implements it. If the implementation reveals a wrong assumption, update the decision instead of quietly drifting away from it.&lt;/p&gt;

&lt;p&gt;Amlaak keeps six of these in its repository, next to the code, from “Modular monolith, not microservices” to “Transactional outbox &amp;amp; Odoo adapter”. Some decisions come straight from a constraint: Happy Ticket runs on Blazor Server so a small team could ship fast.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What user or operational problem are we solving?&lt;/li&gt;
&lt;li&gt;Which constraints are fixed, and which are only preferences?&lt;/li&gt;
&lt;li&gt;What is deliberately outside this change?&lt;/li&gt;
&lt;li&gt;How will we know the decision is wrong in production?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Break work down by risk, not by technical layer
&lt;/h2&gt;

&lt;p&gt;Separate backend, frontend, database, and deployment tickets can look tidy while hiding the fact that nothing works until all four finish. A thin vertical slice gives the team an earlier integration point and makes unclear contracts visible.&lt;/p&gt;

&lt;p&gt;Start with the part that can invalidate the plan: an external API, a migration on real-shaped data, a permission boundary, a slow query, or an unfamiliar deployment target. Proving that boundary early is more useful than completing the easiest files first.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Name one user-visible or operator-visible outcome.&lt;/li&gt;
&lt;li&gt;Identify the riskiest assumption inside that outcome.&lt;/li&gt;
&lt;li&gt;Create the smallest vertical slice that can test it.&lt;/li&gt;
&lt;li&gt;Add acceptance notes, edge cases, and rollback needs before assignment.&lt;/li&gt;
&lt;li&gt;Give one person ownership of the slice while making dependencies explicit.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Choose hands-on work that improves the team
&lt;/h2&gt;

&lt;p&gt;The lead should not automatically take the most visible feature. Better hands-on work often sits at a boundary: the first implementation of a pattern, a risky integration, a production defect with unclear ownership, or tooling that removes repeated friction.&lt;/p&gt;

&lt;p&gt;After proving a pattern, leave an example and hand the next use to someone else. If only the lead can extend it, the code did not create leverage. It created another dependency.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prototype the uncertain part.&lt;/strong&gt; Use a narrow branch or spike to prove feasibility, then turn the result into team-owned production work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build the first reference path.&lt;/strong&gt; Implement one complete example when the team needs a concrete pattern more than another document.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Debug across boundaries.&lt;/strong&gt; Step in when the failure crosses application, database, network, and deployment layers, then share the diagnosis.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In practice.&lt;/strong&gt; On Zotic that meant writing the tenant isolation, the ticket encryption and the Telr integration; on Amlaak, the Odoo outbox and MFA enrolment; on Project Pavilion, the RAG path. Each one is a boundary where a mistake is expensive.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Review the contract before the style
&lt;/h2&gt;

&lt;p&gt;A useful review starts with behaviour. Does the change match the task? Does it preserve tenant and permission boundaries? What happens on retry, cancellation, or partial failure? Can it be deployed and rolled back safely?&lt;/p&gt;

&lt;p&gt;Style and naming still matter, but automated tools should handle mechanical rules where possible. Human review time is better spent on assumptions, domain behaviour, data changes, security, and operational cost.&lt;/p&gt;

&lt;p&gt;Amlaak keeps its review rules in the repository. Findings run from P0, a release blocker, to P3, optional, and each one has to name the file and lines, the behaviour it affects and a test that would prove it fixed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ask for a smaller pull request when unrelated decisions are mixed together.&lt;/li&gt;
&lt;li&gt;Write comments that explain the risk, not only the preferred edit.&lt;/li&gt;
&lt;li&gt;Separate blocking correctness issues from optional improvements.&lt;/li&gt;
&lt;li&gt;When a pattern repeats, improve the shared rule, test, or example instead of leaving the same comment again.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Keep deployment inside the definition of done
&lt;/h2&gt;

&lt;p&gt;A feature is not finished when it works on a developer machine. The work item should name configuration changes, migrations, health checks, logs, rollback steps, and any manual action needed in the target environment.&lt;/p&gt;

&lt;p&gt;The lead does not need to press every deployment button. The lead does need to make the path understandable and ensure more than one person can operate it. Pair on the first release of a new path, record the result, then rotate ownership.&lt;/p&gt;

&lt;p&gt;Amlaak’s deploy workflow waits for the new containers to report healthy, puts the previous images back if they do not, and ends with a smoke test against the public site. Alreef’s deploy script gives a new container two minutes to turn healthy, rolls back to the exact image that ran before, and moves the latest tag only after the new one passes.&lt;/p&gt;

&lt;h2&gt;
  
  
  A simple operating loop
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;One loop from decision to production learning&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Stage&lt;/th&gt;
&lt;th&gt;Concrete output&lt;/th&gt;
&lt;th&gt;Question to answer&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Decide&lt;/td&gt;
&lt;td&gt;Short decision note&lt;/td&gt;
&lt;td&gt;Why this approach under these constraints?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Slice&lt;/td&gt;
&lt;td&gt;Small vertical work items&lt;/td&gt;
&lt;td&gt;What can be delivered and checked independently?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Implement&lt;/td&gt;
&lt;td&gt;Reference path or owned feature slice&lt;/td&gt;
&lt;td&gt;Where is direct lead involvement most useful?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Review&lt;/td&gt;
&lt;td&gt;Risk-focused feedback and tests&lt;/td&gt;
&lt;td&gt;Does the behaviour hold at its boundaries?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Release&lt;/td&gt;
&lt;td&gt;Runbook, health signal, and rollback path&lt;/td&gt;
&lt;td&gt;Can the team operate this change safely?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Learn&lt;/td&gt;
&lt;td&gt;Updated decision, task template, or shared pattern&lt;/td&gt;
&lt;td&gt;What should be easier next time?&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Warning signs
&lt;/h2&gt;

&lt;p&gt;The balance is wrong when every technical question waits for the lead, pull requests remain open because one reviewer is overloaded, or the lead works on hidden emergency code that nobody else understands. It is also wrong when architecture decisions have no contact with production behaviour.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Move routine decisions into examples, tests, and short decision records.&lt;/li&gt;
&lt;li&gt;Give review ownership to the engineers closest to the area, with a clear escalation path.&lt;/li&gt;
&lt;li&gt;Keep a small amount of direct implementation work, chosen for learning and risk reduction.&lt;/li&gt;
&lt;li&gt;Review incidents and deployments with the team, then change the working system rather than relying on memory.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Where this runs
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;On Zotic I led architecture and delivery across the API, the organiser dashboard and the Flutter app, wrote the tenant isolation, the ticket encryption and the Telr integration myself, and ran code review and release. (&lt;a href="https://anasamin.dev/work/zotic/" rel="noopener noreferrer"&gt;Zotic case study&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;On Amlaak I set the architecture and its six decision records, wrote the Odoo outbox and the MFA enrolment, and owned the test strategy, CI and the Docker deployment. (&lt;a href="https://anasamin.dev/work/amlaak/" rel="noopener noreferrer"&gt;Amlaak case study&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;On Happy Ticket I chose Blazor Server so a small team could ship fast, then wrote the tenant isolation, the seat-inventory model and the Telr integration. (&lt;a href="https://anasamin.dev/work/happy-ticket/" rel="noopener noreferrer"&gt;Happy Ticket case study&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://anasamin.dev/notes/hands-on-engineering-leadership/" rel="noopener noreferrer"&gt;anasamin.dev&lt;/a&gt;. I'm Anas Amin, a software engineer in .NET and the founder of &lt;a href="https://arkedia.dev" rel="noopener noreferrer"&gt;Arkedia&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>engineeringleadership</category>
      <category>delivery</category>
      <category>codereview</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>Same Prompt, Two Runs, 13 Points Apart: Why My .NET Eval Gate Needed a Third Answer</title>
      <dc:creator>MICHAEL-MAURICE</dc:creator>
      <pubDate>Tue, 17 Nov 2026 12:51:23 +0000</pubDate>
      <link>https://dev.to/michael_maurice/same-prompt-two-runs-13-points-apart-why-my-net-eval-gate-needed-a-third-answer-137i</link>
      <guid>https://dev.to/michael_maurice/same-prompt-two-runs-13-points-apart-why-my-net-eval-gate-needed-a-third-answer-137i</guid>
      <description>&lt;p&gt;I ran the exact same prompt against the exact same 120 test cases, twice, with different seeds. Then I did it 30 times.&lt;/p&gt;

&lt;p&gt;The pass rates differed by up to &lt;strong&gt;13.3 points&lt;/strong&gt; between two runs that changed nothing. My old CI rule, "block the build if the score drops more than 3 points below baseline", would have blocked &lt;strong&gt;8 of those 30&lt;/strong&gt; builds. Eight red pipelines, zero real regressions.&lt;/p&gt;

&lt;p&gt;That's the part of LLM evaluation nobody puts on the dashboard: one eval run is a sample, not a measurement. This post is about one narrow piece of the fix, the gate itself, and why "pass or fail" is the wrong shape for it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tech Skill Builder is $5/month for a very limited time only (normally $10). Grab it now before it goes back to $10.&lt;/strong&gt; The complete, tested project behind this post (a .NET 10 eval service with Clean Architecture, judge calibration, paired gates and 215 passing tests, running offline against a simulator) plus a step-by-step PDF guide is inside. &lt;a href="https://elitesolutions1.gumroad.com/l/TechSkillBuilder" rel="noopener noreferrer"&gt;Join Tech Skill Builder&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;About the numbers: all of them are my own local measurements with a **seeded simulator&lt;/em&gt;* playing the model and the judge. They show how the statistics behave, not how good any real model is.*&lt;/p&gt;

&lt;h2&gt;
  
  
  The gate most of us start with
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// The naive gate: compare two averages, apply a threshold.&lt;/span&gt;
&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nc"&gt;ShouldBlock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;baselinePassRate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;candidatePassRate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;baselinePassRate&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;candidatePassRate&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.03&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It looks reasonable. It has three hidden problems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;It ignores noise.&lt;/strong&gt; Two averages from noisy runs differ even when nothing changed, and a fixed threshold doesn't know how noisy your runs are.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It throws away pairing.&lt;/strong&gt; Both runs used the &lt;em&gt;same&lt;/em&gt; cases. A hard case is hard for both. Comparing two averages discards that, so the noise from case difficulty stays in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It only has two answers.&lt;/strong&gt; When the evidence is weak, it still has to say "ship" or "block". So it guesses, and you can't tell a guess from a verdict.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Fix 1: Compare per case, not per run
&lt;/h2&gt;

&lt;p&gt;Since both runs answered the same cases, compute the difference &lt;em&gt;for each case&lt;/em&gt; and look at the distribution of those differences.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;record&lt;/span&gt; &lt;span class="nc"&gt;CaseResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;CaseId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;Passes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;Samples&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;Rate&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nc"&gt;Passes&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nc"&gt;Samples&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;IReadOnlyList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;PairedDiffs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nc"&gt;IReadOnlyDictionary&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;CaseResult&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;baseline&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;IReadOnlyDictionary&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;CaseResult&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Only cases present in both runs count. Missing cases are a bug, not a zero.&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;ids&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;baseline&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Keys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Intersect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Keys&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OrderBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;StringComparer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Ordinal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rate&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;baseline&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A case that both runs fail contributes 0. Only the cases where the runs &lt;em&gt;disagree&lt;/em&gt; move the result. That alone removes most of the "13 points apart" noise.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fix 2: Put an interval around the mean difference
&lt;/h2&gt;

&lt;p&gt;A single mean difference is still a point estimate. Bootstrap it: resample the &lt;strong&gt;cases&lt;/strong&gt; (not the individual samples) many times and take the 2.5th and 97.5th percentiles.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="k"&gt;record&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;Interval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;Low&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;Point&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nc"&gt;High&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Interval&lt;/span&gt; &lt;span class="nc"&gt;MeanCi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IReadOnlyList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;diffs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;resamples&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;ulong&lt;/span&gt; &lt;span class="n"&gt;seed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;rng&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DeterministicRandom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;seed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// seeded, so CI gets the same answer on every machine&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;stats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;resamples&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// ... resample diffs with replacement, store each mean, sort, read percentiles&lt;/span&gt;
    &lt;span class="c1"&gt;// full implementation (plus the clustered version for repeated samples) in the complete project&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NotImplementedException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details matter more than the code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Seed it yourself.&lt;/strong&gt; Don't feed &lt;code&gt;string.GetHashCode()&lt;/code&gt; into a seed; it's randomized per process in .NET, and your gate would give different answers on different agents.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The case is the unit of independence.&lt;/strong&gt; 120 cases run 5 times is 600 results, but only 120 independent things. In my runs, treating them as 600 gave an interval &lt;strong&gt;6.7 points wide&lt;/strong&gt;; resampling by case gave &lt;strong&gt;9.8 points&lt;/strong&gt;. The narrow one was simply wrong.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Fix 3: Three answers, not two
&lt;/h2&gt;

&lt;p&gt;Now the gate can say what the evidence actually supports. Pick a tolerance (how much drop you'll accept, say 3 points) and look at both ends of the interval:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="nc"&gt;GateDecision&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Ship&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Block&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;NeedMoreData&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;GateDecision&lt;/span&gt; &lt;span class="nc"&gt;Decide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Interval&lt;/span&gt; &lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;tolerance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Low&lt;/span&gt;  &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;tolerance&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nc"&gt;GateDecision&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Ship&lt;/span&gt;          &lt;span class="c1"&gt;// even the pessimistic end is acceptable&lt;/span&gt;
  &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;High&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;tolerance&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nc"&gt;GateDecision&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Block&lt;/span&gt;         &lt;span class="c1"&gt;// even the optimistic end is too bad&lt;/span&gt;
  &lt;span class="p"&gt;:&lt;/span&gt;                          &lt;span class="nc"&gt;GateDecision&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NeedMoreData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// honestly undecided&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a non-inferiority check. You ship only when the &lt;em&gt;worst plausible&lt;/em&gt; reading is fine, and you block only when the &lt;em&gt;best plausible&lt;/em&gt; reading is still bad.&lt;/p&gt;

&lt;p&gt;On those same 30 identical-config pairs, this gate blocked &lt;strong&gt;0 of 30&lt;/strong&gt;. And a clearly broken prompt (about 22 points worse) was still blocked straight away. Fewer false alarms, no missed disasters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fix 4: Make "NeedMoreData" actionable
&lt;/h2&gt;

&lt;p&gt;"Undecided" is only useful if it tells you what would decide it. A standard sample-size estimate does that, using the spread of &lt;em&gt;your own&lt;/em&gt; per-case differences:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Two-sided 5% test, 80% power. A planning approximation, not a proof.&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;CasesNeeded&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;sdOfDifference&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// n â‰ˆ (z_alpha/2 + z_beta)^2 * sd^2 / margin^2&lt;/span&gt;
    &lt;span class="c1"&gt;// full implementation with input validation in the complete project&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NotImplementedException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In my simulator, a prompt that was genuinely a bit weaker showed &lt;strong&gt;-4.5 points, p = 0.0503&lt;/strong&gt; after 5 repeats per case. The old gate would have flipped a coin. The new one said: &lt;em&gt;"About 695 cases are needed to settle it; you have 120."&lt;/em&gt; That's a conversation you can actually have with your team.&lt;/p&gt;

&lt;p&gt;Rule of thumb: halve the margin and you need four times the cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two traps that make the gate lie anyway
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Different judges.&lt;/strong&gt; If run A was graded by one LLM judge and run B by another (or by the same model with a new judge prompt), the scores aren't on the same scale. I refuse the comparison outright:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;JudgeId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;JudgeId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;StringComparison&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Ordinal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DomainException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ErrorKind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Conflict&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"judge_mismatch"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// the API maps this to a 409 with a stable code, so a CI script can branch on it&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(And before any of this, the judge itself needs checking against human labels. A judge that agrees with humans 90% of the time can still be close to useless; that's its own topic.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adaptive sampling.&lt;/strong&gt; It's tempting to stop sampling a case once its first 3 runs agree. In my test, that cut model calls by &lt;strong&gt;38%&lt;/strong&gt; and pushed the pass rate from &lt;strong&gt;76.8% to 83.5%&lt;/strong&gt;, because early stopping favours the easy cases. Cheap and wrong. Don't gate on a number from an adaptive run; re-run with fixed repeats.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist before your eval gate blocks a deploy
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Both runs used the same case set, and you compare &lt;strong&gt;per case&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The interval resamples &lt;strong&gt;cases&lt;/strong&gt;, not individual samples.&lt;/li&gt;
&lt;li&gt;The bootstrap is &lt;strong&gt;seeded&lt;/strong&gt; with your own deterministic RNG.&lt;/li&gt;
&lt;li&gt;The gate has three outcomes, and &lt;strong&gt;NeedMoreData&lt;/strong&gt; comes with a case count.&lt;/li&gt;
&lt;li&gt;Both runs were graded by the &lt;strong&gt;same, calibrated judge&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;No adaptive or early-stopped runs feed the gate.&lt;/li&gt;
&lt;li&gt;A provider outage fails the run (502), it never shows up as a quality drop.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's in the full version
&lt;/h2&gt;

&lt;p&gt;The snippets above are skeletons: the shape of each piece, with the bodies left out. The complete project in Tech Skill Builder is a working .NET 10 eval service (Domain / Application / Infrastructure / Api, plus unit and integration tests, 215 passing) with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;judge calibration with Cohen's kappa and a bootstrap interval, failing closed on unusable verdicts,&lt;/li&gt;
&lt;li&gt;Wilson and clustered bootstrap intervals,&lt;/li&gt;
&lt;li&gt;the paired Ship / Block / NeedMoreData gate and the case planner,&lt;/li&gt;
&lt;li&gt;the judge-mismatch and adaptive-run guards,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;IChatClient&lt;/code&gt; adapters so OpenAI, Azure OpenAI or Ollama can plug in, and a seeded simulator so everything runs offline,&lt;/li&gt;
&lt;li&gt;a PDF guide that walks through the architecture and every decision.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://elitesolutions1.gumroad.com/l/TechSkillBuilder" rel="noopener noreferrer"&gt;Get the complete, tested project in Tech Skill Builder: $5/month for a very limited time (normally $10). Grab it now before it goes back to $10.&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;How does your team decide an eval drop is "real" today: a fixed threshold, a human looking at the diff, or something statistical? I'm curious what's held up in practice.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>ai</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
