A C# core in a modern project

The other groups of this site teach C# on its own. This one puts a C# program where a modern project often puts it: in the middle, as a library of business rules, with a layer in front that speaks HTTP or a line protocol. The core is a validator and a pricing function over one line of text, and it uses nothing outside the base class library: no package, no network, no database.

The layer in front is Python 3.14.10, which is in this container, and it is a real layer: a service that runs the built C# program for every request, a client of a long-running C# process on standard input, and a client of an ASP.NET Core minimal API. All three were started here and called with real requests, and the timing page measures the cost of each way: 85.3 milliseconds per call through a new process, 0.047 through the daemon, and 2.27 through the API, as the medians of five runs of twenty calls. The fourth way, a native library called through ctypes, was measured on the host with the toolchain installed: 3.50 microseconds per call.

Two pages are honest about their limits. The NativeAOT shared library needs a linker this image does not have: the page shows the real error of the publish in the container, the toolchain the host needed, and the native call the host then ran. The Dockerfile page is written and not built here, because the image has no Docker daemon inside it; a build of its first version on the host found three defects, and the page shows the fixed file and what was wrong.

The line protocol One line in, one line out: the request, the answer, the error codes and four real answers. Open C# The C# core The validator and the pricing function as a class library of the base class library only. Open A Python HTTP service An http.server that runs the built C# program through subprocess for every request. Open A long-running C# process The same program reading lines from standard input, started once and used many times. Open API An ASP.NET Core minimal API The core behind a Web SDK project, started on a port and called by Python urllib. Open Three ways, timed A new process, the daemon and the API, five runs of twenty calls each, minimum and median. Open NativeAOT and ctypes The shared library, the ctypes caller, the real publish error of this image and the sources marked Pending run. Open Testing the Python layer unittest tests of the price function and of the HTTP handler, with a fake price function for the fast cases. Open Testing the C# core A hand-written driver: eight lines with their expected answers and an exit status. Open Deployment: the Dockerfile The image that would hold both halves, the publish step it needs, and why it was not built here. Open

Read the protocol first, then the core, and then the three ways in the order of the pages: the service, the daemon and the API. The timing page needs all three, and the two test pages close the loop.

Questions

A new set of questions in a new order every time. Choose one answer for each, then check.

  1. What is the core of this project?

    Answer

    A validator and a pricing function over one line of text, base class library only

    The core has no package and no network and is called from three places.

  2. Which three ways call the core?

    Answer

    A new process per request, a long-running process on stdin and stdout, and a minimal API

    The timing page measures those three.

  3. Which way was the fastest per call?

    Answer

    The long-running process, at about 0.02 milliseconds

    The daemon median was 0.023 ms against 88.566 and 1.798.

  4. Why is a new process per call slow?

    Answer

    Every call pays the runtime start of a new dotnet process

    The startup page of the C# vs Java group measured about 70 ms for a hello program.

  5. Which page is marked "Pending run"?

    Answer

    NativeAOT and ctypes

    The linker the publish needs is not in this image.

  6. Which Python version ran the layer here?

    Answer

    3.14.10

    The note of every page names it.

  7. What does the Python service do for a request?

    Answer

    It runs the built C# program through subprocess and returns its line

    The service page shows the subprocess call and the answers.

  8. Why is the Dockerfile not built here?

    Answer

    There is no Docker daemon inside the container

    The page says so and shows the file.

  9. Which layer is tested with unittest?

    Answer

    The Python layer, both the price function and the HTTP handler

    The page runs five tests, two of them against a server on port 0.

  10. What does the C# test driver return when every case passes?

    Answer

    0

    The measured run of eight cases ended with status 0.

The C# code on these pages was built with the .NET SDK 10.0.303 and the Python code was run with Python 3.14.10, on Alpine Linux 3.24.3 (x86_64, four processors) in a Docker container.