Preface
Who This Book Is For and What You Need to Know
This book is for .NET developers who want to use the C# skills they already have to build interactive UIs.
You do not need to have written front-end code. How components are laid out, how styles are adjusted, how requests are sent and how the page updates are all handled by Gradio.NET; what you write is a C# method that takes input and returns a result, plus a few lines that wire it to the UI. You do not need to know Python either. Every example in this book is C#, and the Python version of Gradio is not involved.
What you do need is C# itself, including generics, nullable reference types and everyday collection operations. For asynchronous programming, you should be able to read async/await and Task; the book uses them heavily from Chapter 16 on, and barely at all in the first fifteen chapters. You should also have a basic grasp of HTTP: what a request and a response are, what a status code means, and what happens when a browser opens an address. ASP.NET Core experience helps — Chapter 21 mounts an application directly on it — but not having it does not affect the first twenty chapters.
The book does not require any of the following: experience with web front-end frameworks, machine learning knowledge, or databases. Chapter 16 connects to a real model service, but that chapter is about streaming output, not machine learning.
Software Versions and Target Framework
Every example is based on the Gradio.Net NuGet package 0.6.30.8 and targets net10.0.
The target framework net10.0 requires the .NET 10 SDK. Run dotnet --version on the command line; the output should start with 10.. The global.json at the repository root pins the SDK’s major version and roll-forward policy, so a machine with several SDKs installed will not silently switch to another major version. If that command reports that no matching SDK was found, install the .NET 10 SDK before continuing.
Beyond .NET itself, the examples need no Python, no separate front-end build and no Node.js. Gradio.NET ships its front-end assets with the NuGet package.
Where the Chapter Samples Are and How to Get Them
Each chapter has its own sample project. In this English edition they live in samples-en\chapterNN — Chapter 5, for example, is in samples-en\chapter05.
“Own” means this. Take any one chapter’s directory and you can run it without having done the earlier chapters. Each sample carries every source file, configuration file, sample data file and pinned dependency version it needs, and does not depend on other chapters through project references, linked files or runtime paths. You can unpack only the Chapter 12 material, skip the first eleven chapters, and it still builds and runs.
A chapter’s sample shows the state of the application as of that chapter. It contains the modules explained in earlier chapters, but not things that only come up later. So the Chapter 12 sample is a working workbench with the earlier modules already installed, not an empty shell that only demonstrates file upload. That way, when you read a chapter, all the code you see has already been explained.
The code snippets in the main text all come from these sample projects. A snippet is trimmed to make one point clear, but the trimmed code still compiles inside that chapter’s project; where a piece of illustrative code cannot compile, the text says explicitly that it is illustrative.
One Way to Restore, Build, Launch and Stop
All chapters use the same set of commands; only the project name changes. The commands below run in Windows PowerShell from the repository root, using Chapter 5 as the example.
dotnet restore samples-en\chapter05\Chapter05.csproj
dotnet build samples-en\chapter05\Chapter05.csproj --configuration Release --no-restore
dotnet run --project samples-en\chapter05\Chapter05.csproj --configuration Release --no-build --no-restore
Each of the three commands does one thing. restore fetches dependencies. build compiles, and --no-restore means it does not repeat the restore. run launches the application, and --no-build and --no-restore mean it uses the output of the previous step directly.
Once it starts, the console prints an address.
Running on local URL: http://127.0.0.1:7860/
Open that address in a browser and you have the application’s UI. Stop it with Ctrl+C; once the process exits, the port is released.
For other chapters, replace chapter05 and Chapter05 in the commands with the corresponding chapter number; everything else stays the same. The book does not repeat these three commands chapter by chapter.
Each sample pins Gradio.Net to 0.6.30.8 in its PackageReference rather than using a version range, so restore gets exactly the version the sample locks. The samples ship no lock file, and you are not required to understand lock files first.
The Chapter 16 sample needs a connection to an OpenAI-compatible model service. Its address and credentials are supplied at runtime through environment variables; the chapter gives the variable names and how to use them. These values are not written into code, configuration files or sample data, and are not distributed with the repository. Without them, the sample reports the missing configuration and stops — it does not invent a reply.
Port Conflicts and Common Startup Problems
The default port is 7860. If it is already in use — most often because an application you started earlier has not been stopped — startup fails and prints:
System.IO.IOException: Failed to bind to address http://127.0.0.1:7860: address already in use.
The process then exits rather than hanging. First find out what is holding the port.
Get-NetTCPConnection -LocalPort 7860 -State Listen | Select-Object OwningProcess
Get-Process -Id <process ID from the previous command>
Decide only after you know which process it is. If it is an application you started, stop it; if it belongs to someone else or to other software, do not stop it — use a different port instead. Pass the port in when launching:
demo.Launch(serverPort: 7861);
Besides ports, there are two other classes of problem worth knowing up front.
The first is a failed dependency restore. Most often a package cannot be found, which is usually a NuGet source configuration issue; check the output of dotnet nuget list source for a usable source. Next most common is a version conflict, usually because you edited the PackageReference in the project file; change it back to 0.6.30.8 and restore again.
The second is an SDK version mismatch. The error message mentions global.json and the required major version. Install the SDK it asks for, or use dotnet --list-sdks to see exactly which versions are on your machine.
The book has no separate appendix for these problems; come back to this section when you hit one.
How to Read the API Snippets in the Text
The text writes code in C#. Components are created through the factory methods under gr, for example gr.Textbox() and gr.Blocks(). Parameter names match the library’s public parameters, so you can compare them directly.
Look at the return type first. In Gradio.NET the most common mistake is a mismatch between what a handler function returns and what an output component expects. When a component is first introduced, the book states explicitly what type it passes to the handler function and what type it accepts back; that is not repeated later.
Next, check whether this is where the capability first appears. The book advances by capability, and each concept is explained in detail only in the chapter where it is introduced. Later mentions give a chapter number instead of explaining it again. If you meet an unexplained type in a chapter, going back to where it first appeared is usually faster than looking for an explanation there.
Read the sentence outside the code block too. What a parameter actually does, where its boundaries are and how it fails are often invisible in the code — whether a limit rejects or truncates, whether an event coalesces or drops. Those conclusions sit beside the code and come from running it, not from guesswork.
This book covers only the public API and observable behavior; it does not dissect the library’s internal implementation. Every behavior described here can be reproduced with the samples. Implementation details can change and are not a promise. Where the book has not verified something, the text says so rather than stating it as a conclusion.
The references at the end of the book list the addresses used to check APIs and protocols: the package page, the source repository, the XML documentation inside the package, and the official documentation for .NET, ASP.NET Core and OpenAI-compatible interfaces. When a behavior in the text comes from those documents rather than from a run, the text says so.
A Note on This English Edition
This edition is a full translation of the Chinese original. Nothing is left in Chinese: the sample data, example strings, API names, C# identifiers and every figure have been reworked for English readers.
The sample data is English. The workbench examples wrap, count and split English text by character. The English corpus was written so that every line length, character count, truncation position and quoted output fragment in the book still matches what the samples actually produce. This applies to SampleText values, the assets/*.txt and assets/*.csv files, and the strings shown as the output of those operations.
The screenshots and diagrams were regenerated from the English samples, so all UI text visible in a figure is English. Figure captions describe what the figure shows.
All sample projects for this edition live in samples-en/, a copy of samples/ with code comments, UI strings, sample data, identifiers, API names and project metadata translated. File names, versions and command-line syntax are unchanged, so the code you read here compiles against the same Gradio.Net 0.6.30.8 package as the Chinese edition. Use the samples-en paths in every command.