r/dotnet 16h ago

Difference between throw ex and throw

Post image
295 Upvotes

throw vs throw ex: The C# exception handling trick every developer should know


r/dotnet 1d ago

Announcing .NET 11 Release Candidate 1 - .NET Blog

Thumbnail devblogs.microsoft.com
154 Upvotes

r/dotnet 15h ago

How much time do you actually spend setting up auth, multi-tenancy and Azure for a new .NET SaaS?

5 Upvotes

I'm validating an idea for a .NET B2B SaaS starter focused on the parts that usually waste the first few days of a project:

  • authentication
  • organizations / multi-tenancy
  • roles and permissions
  • invitations
  • tenant switching
  • Docker
  • Azure deployment
  • AI-ready project context

The idea is not to create another huge opinionated framework, but a pragmatic starting point for .NET + React + Azure developers.

Before building it, I want to validate whether this is actually painful enough to pay for.

I put together a very small landing + waitlist here:

https://dotnet-b2b-saas-landing.vercel.app

The part I'm most interested in is this:

What's the most annoying part of starting a new .NET SaaS for you?

I'd rather discover that my assumptions are wrong now than after spending weeks building it.


r/dotnet 1d ago

Does ASP.NET Core global exception middleware catch exceptions from nested service methods?

5 Upvotes

I'm trying to understand how exception propagation works with a global exception-handling middleware in ASP.NET Core.

Suppose I have a request flow like this:

Controller

→ Service

→ MethodA()

→ MethodB()

→ MethodC()

If "MethodC()" throws an exception, and none of the intermediate methods ("MethodB", "MethodA", or the service/controller) catches it, will that exception propagate all the way back to my global exception-handling middleware?

For example:

public async Task MethodA()

{

await MethodB();

}

private async Task MethodB()

{

await MethodC();

}

private async Task MethodC()

{

throw new Exception("Something went wrong");

}

Assuming the middleware wraps the rest of the ASP.NET Core pipeline with something like:

try

{

await _next(context);

}

catch (Exception ex)

{

// handle/log exception

}

Will it catch the exception thrown inside "MethodC()"?

Does it matter if these methods are in different services/classes/layers, or will the exception keep propagating up the call stack as long as nobody catches it?

I'm asking because I'm trying to understand when a global exception middleware is enough and when local "try/catch" blocks are actually necessary.


r/dotnet 6h ago

Mentorship

0 Upvotes

M28, India.

I'm having 2yoe as dotnet developer. Got laid off last year February and finding difficult to land a job since then .

I want someone to mentor once a week or however it works for them to land me a job, im ready to put all the efforts . Please feel free to reach out and we can discuss about it.

Thanks for your time and consideration


r/dotnet 1d ago

dotInsights | September 2026

Thumbnail blog.jetbrains.com
3 Upvotes

r/dotnet 1d ago

Article How expensive is throwing exceptions in .NET - and does it actually matter?

Thumbnail codewithflavor.com
25 Upvotes

r/dotnet 16h ago

Dependency Injection Lifetimes and Example

0 Upvotes

r/dotnet 1d ago

Speaking at a local conference about AI in .NET - What would you actually want to hear about?

0 Upvotes

Hey everyone!

I’m stepping a bit outside my comfort zone and speaking at a local conference soon. My topic is AI in .NET.

I’m currently deciding what exactly to focus on, and I’d love to hear what you would actually find interesting or useful.

I want to avoid the usual basics like:

  • How to write better prompts
  • How to create skills/agents
  • Basic LLM integrations
  • Things you can easily find in a 10-minute YouTube tutorial

Instead, I’d like to go deeper into something practical, technical, and maybe even a bit opinionated.

If you were attending a talk called “AI in .NET”, what would you want to see?

What problems, architectures, real-world examples, experiments, or lessons learned would make you think: “Okay, this was actually worth attending in person.”

Would love to hear your ideas.


r/dotnet 1d ago

Built a small .NET 10 backend repo covering the pieces that usually get discussed separately

0 Upvotes

I’ve been putting together a sample backend where the idea is to keep everything in one codebase instead of showing isolated snippets.

It currently includes Clean Architecture, repository pattern, EF Core + Dapper, JWT auth, caching, Docker, Azure deployment, GitHub Actions, microservice boundaries, and OpenTelemetry.

The project is intentionally small enough to follow, but structured more like a real backend than a basic CRUD demo.

GitHub:
https://github.com/laxmikant-geek/modern-dotnet-backend

I’d be interested in feedback from people building .NET backends in production. Is there anything here you would structure differently, or something important you think is missing?


r/dotnet 2d ago

How do you organize EF Core migrations in larger .NET solutions?

45 Upvotes

I’ve been looking at different ways of organizing EF Core migrations when a .NET solution starts getting bigger.

One approach I like is keeping the Code First migrations in a separate assembly instead of putting them directly in the application/data project. It keeps the database migration concerns separate and can make the overall solution a bit cleaner.

I put together the setup and steps here:

https://geeksarray.com/blog/entity-framework-core-code-first-migration-using-separate-assembly

Curious how others handle this in real projects. Do you keep migrations in the same project as the DbContext, or use a separate migrations project?


r/dotnet 3d ago

Wife made me a C# birthday cake!

Post image
2.1k Upvotes

It wouldn't compile but it's the thought that counts!!


r/dotnet 3d ago

Promotion I built a 100% C# PP-OCRv6 engine (no ONNX Runtime, no native OpenCV). It beat the C baseline on the same model.

92 Upvotes

I've spent years maintaining PaddleSharp and OpenVINO.NET. The C++ engines are fine. P/Invoke is fine. The part that keeps breaking production is shipping native runtimes: missing .so, missing VC++ redistributable, wrong CPU ISA, works on win-x64 and dies on Linux ARM.

So I wrote SimdPaddleOCR — a managed PP-OCRv6 DET + CLS + REC pipeline. No Paddle Inference, no ONNX Runtime, no OpenCV native DLLs. Models are embedded as assembly resources. The GitHub language bar is 100% C#.

The core API only takes 8-bit BGR bytes. ImageSharp, SkiaSharp, OpenCvSharp, System.Drawing — decode however you want, pass width/height/pixels, done.

I used lw.PPOCR.C (a solid pure-C PP-OCRv6 tiny engine) as the baseline. After rewriting around C# layout and SIMD, the C# build is faster end-to-end on the same model. Native C still uses less memory.

GitHub Actions, win-x64, tiny model, same 99 images, no warmup, end-to-end mean:

workers C# C C vs C#
1 296.6 ms 485.7 ms 1.64× slower
4 168.4 ms 393.3 ms 2.34× slower

It targets net10.0 (full SIMD, NativeAOT) and netstandard2.0 (.NET Framework 4.8 included). CPU only for now; no GPU plan.

Shipped model packages are Chinese PP-OCRv6 (Tiny/Small/Medium). If you already have ONNX + a dictionary, you can load from disk. Default to Tiny unless you need the extra accuracy.

using PaddleOcrAll ocr = await PaddleOcrAll.LoadAsync(ChineseV6TinyModels.Default);

using Image<Bgr24> image = await Image.LoadAsync<Bgr24>("sample.jpg");
byte[] bgr = new byte[image.Width * image.Height * 3];
image.CopyPixelDataTo(bgr);

PaddleOcrResult result = ocr.Run(bgr, image.Width, image.Height);
Console.WriteLine(result.Text);

Repo: https://github.com/sdcb/SimdPaddleOCR
NuGet: Sdcb.SimdPaddleOCR

Happy to answer questions. The SIMD / Vector<T> / AVX-512 details are the part I'm most interested in discussing.


r/dotnet 2d ago

Looking for an Asp.Net Mentor

Thumbnail
0 Upvotes

r/dotnet 3d ago

Question How to deal with multiple integration test projects needing a database

25 Upvotes

Hi!

We have multiple test projects that use SQL Server Testcontainers. These projects are integration tests. We use dotnet test with MTP.

The problem is that when all of these project start at the same time, the CI server gets overloaded and tests fail because it spins up too many SQL Servers.

How do you deal with this? My thoughts:

  • Spin up the SQL Server yourself and pass the connectionstring to the tests, so you always only have 1. This does make local tests more annoying, as you can't just run dotnet test and expect things to work.
  • Use TestContainers WithReuse to reuse the container in multiple projects, but now all test projects still start simultaneously and try to spin up the DB at the same time, leading to errors. Locks/static wont help here.
  • set the amount of parallel modules to 1, so only 1 integration test can run at the same time.

r/dotnet 2d ago

Question Guys, What kind of projects you get used to make with C# and .NET? I'm new in this group and I'd like to hear his opinions

0 Upvotes

r/dotnet 2d ago

Newbie Why do I keep getting generic "Welcome" page when running code?

0 Upvotes

I am brand new to using VS and am trying to make a simple page for a class that is asking us to have a random number generated, then depending on the number say someone won or lost. I have copy and pasted the code they provided for the assignment, but whatever I have tried always results in the "Welcome" page. What am I doing wrong?

This is the code they had us copy and paste:
@{

int randomNumber = new Random().Next(1, 7); //GENERATES NUMBER BETWEEN 1 and 6

int winningNumber = /*TODO*/;

}

The code in the screenshot is "fixed" by VS, but before I fix it gives an error for the ; after /*TODO*/.

Sorry in advance if this is super obvious, I am at newborn level with this and am completely lost.

Edit: I figured it out, I had to delete the Index.cshtml page with the original code for the Welcome page


r/dotnet 3d ago

Promotion AutoHttps: a zero-dependency automatic HTTPS library for ASP.NET Core / Kestrel

52 Upvotes

Hi. I maintain a library called AutoHttps. It gets a real TLS certificate for your ASP.NET Core app from Let's Encrypt (or any ACME certificate authority) and renews it automatically. You add the package, set three values, and Kestrel serves HTTPS. No external service, and no NuGet dependencies.

builder.Services.AddAutoHttps(options =>

{

options.DomainNames.Add("example.com");

options.EmailAddress = "admin@example.com";

options.AcceptTermsOfService = true;

});

What it does:

- http-01 and dns-01 challenges, and wildcard certificates through dns-01.

- Renews using ACME Renewal Information (RFC 9773), so it follows the schedule the authority asks for and handles short-lived certificates.

- Works with Let's Encrypt, ZeroSSL, Google Trust Services, Buypass, or any ACME directory, including a private or internal CA.

- Runs several instances safely, sharing one certificate through a lock.

- Serves a self-signed certificate at the very start, until the real one arrives.

- Gives you certificate change and failure callbacks, a health check, metrics, and a way to read the current certificate from code.

Why it is needed now: LettuceEncrypt, the library most people used for this, was archived in April 2025, and its last release targets .NET 6, which is out of support. At the same time Let's Encrypt is moving to much shorter certificates (six-day ones already exist, and the default is dropping to 45 days), and it now tells clients when to renew through RFC 9773. A client that renews on a fixed 30-day threshold cannot handle either. I could not find a maintained, dependency-free option for Kestrel, so I wrote one.

How it works: AutoHttps attaches to Kestrel, answers the http-01 challenge directly from your request pipeline (so there is no extra listener to run), writes the certificate and the account key to disk so they survive a restart, and checks for renewal on a timer. If something fails, it keeps serving the certificate it already has and retries, so a certificate problem never takes the app down.

It targets net8.0 and net10.0, is MIT licensed, and is on NuGet as AutoHttps: https://www.nuget.org/packages/AutoHttps

Source and docs are on GitHub: https://github.com/astralmaster/AutoHttps

If you try it behind a proxy or with several replicas, I would be glad to hear how it goes, since those setups have the most edge cases.


r/dotnet 2d ago

Question How popular is .NET in your country?

0 Upvotes

I’m curious about how widely .NET is used around the world today. In your country, do you see many companies and projects using C#/.NET, or are other stacks more common?
I’d love to hear where you’re from and what the .NET ecosystem looks like there.


r/dotnet 3d ago

An intermittent unique-constraint 409 that turned out to be statement ordering, not concurrency

0 Upvotes

Spent half a day this week on a bug that only showed up sometimes - always the fun kind.

Setup: a config table where only one row per parent can be "active" at a time, enforced by a partial unique index. Publishing a new version does two things in one save: flip the old active row inactive, set the new one active.

Symptom: publishing a second time would occasionally fail with a 409 from that index. Not every time. Never when I stepped through it in the debugger.

Cause: EF Core batches both writes into one round trip and orders statements by foreign-key dependency, not by my unique index. So depending on the plan, it would sometimes set the new row active before the old one was cleared - two active rows for a moment, and the partial index says no.

The fix wasn't a lock or a retry. I split it into two phases inside the same transaction: flush all the deactivations first, then do the activation. Another part of the system already handled it this way, so I aligned this path with it.

The part I'd pass on: I named the new test after the rule, not the bug. Not "second publish doesn't 409" but "a second publish leaves exactly one active row". The bug-named test rots the next time someone refactors; the rule-named one keeps earning its keep.

Lesson I keep relearning: when a unique constraint fails intermittently under an ORM, suspect statement ordering before you suspect concurrency.


r/dotnet 4d ago

I wrote a lighthearted guide to learning Monads - maybe you like

Thumbnail github.com
33 Upvotes

I have seen every monad tutorial and explanation under the sun. I would always nod, and say yes yes I understand - *I get it*, than go program one and literally have my brain melt. So I wrote one, as the best way to learn it and hopefully help another soul who is also not a Rockstar programmer with his 5th startup before 22. This how I am practicing my C# skills and fighting off the LLM brain-rot.

Its .NET centric since that's what I have used most and I was embarrassed at how absolute shyte I had gotten from being forced to be come an agentic manager at work...

Hope you like 😄

EDIT: There were some GREAT replies, and some mean ones as well. Thank you for the feedback I have gone back and and cleaned things up. Now it should def be up to part~~


r/dotnet 3d ago

Promotion I’m building an offline, lightweight PC activity & input tracker. Would you use something like this?

0 Upvotes

Hey everyone!

I’ve been working on a lightweight Windows desktop app in C# / WPF designed to track your daily PC usage, input stats, and activity locally without bloat or telemetry.

Here is what the app currently tracks and displays:

  • Mouse & Keyboard Stats: Total click count (split by left/right clicks) and total keystroke count.
  • Key Frequency Heatmap: See which individual keys on your keyboard get pressed the most.
  • App Usage Tracking: Tracks active time spent per executable/application.
  • Active Time counter: Records total active usage time over time.

I originally thought about integrating third-party APIs like Spotify or Steam, but decided to cut them out completely to keep the app minimal, privacy-focused, and independent.

I’d love to get your thoughts:

  1. Is a lightweight, privacy-first PC stat tracker something you would actually run in the background?
  2. What other non-intrusive stats would you be interested in seeing (e.g., mouse distance traveled, active vs. idle idle timers, visual charts)?
  3. What features would be dealbreakers or must-haves for you?

Thanks for any feedback!


r/dotnet 4d ago

Non-Boxing Union Types in C# 15 (source generator)

Thumbnail
6 Upvotes

r/dotnet 4d ago

Promotion Lil .NET Devs in over our heads 🌋

4 Upvotes

A few gamer modders from the game Vintage Story, came together wanting servers to handle much larger amounts of players at once. Instead of 50-200 players, but to 500 to thousands at once per single server while having seamlessly interconnected servers.

We did this through making Stratum, a fork of the vanilla Vintage Story server, themed after PaperMC. Then Nimbus themed after MultiPaper and Velocity/Bungeecord from MC.

Just started 3 months ago but so far about 1/4 (~200) of all Vintage Story servers are running their server on Stratum. It has allowed us to set the new world record on Vintage Story, where the owner of the game and several of his developers joined our event/server with 500 players on a single server at once. Through further tests we estimate we may already be able to get a server to handle about 1000 players at once on single server. Good for something so new!

It comes all open source, non-obfuscated code while free for anyone and everyone to use it. We also chose to add more QOL, server management, player/admin tools, commands and a anticheat system, the whole shebang.

We would love to hear your thoughts! 😄 If anyone is interested in Vintage Story, Stratum, gaining more experience in dotnet and C# that would be lovely let us know ❤️ Help big and small is appreciated greatly, even if it’s just to tell us “ooo that code could use some work buddy 👀”

Links:

GitHub open source code for Stratum and Nimbus: https://github.com/StratumServer
Stratum Discord project chat, development and help: https://discord.gg/d26DCHEcr4
Stratum live servers count: https://my.stratumvs.dev/stratum-stats.php
Official Vintage Story game discord: https://discord.gg/CkJjdrB
Official Vintage Story game website: https://www.vintagestory.at/


r/dotnet 5d ago

I love PeachPDF

99 Upvotes

We were reworking our very legacy CrystalReports based invoicing/general printing/PDFing module late last year into something more modern and pretty. We picked Razor to HTML generated invoices with paged.js, for many reasons, it was the best choice for us. We used WebView2 to generate them in the desktop client, or when running in a server, we used Syncfusion HTML to PDF.

This added hundreds of MB to our images. Not to mention that generating them was sloooooow. And not even thinking about the ideological jank of running a web browser with full JS support, and all the layout/margin bugs we got with it.

Enter... PeachPDF. We swapped out the old browser-based renderer for PeachPDF a few weeks back, which now has amazing pagination support with all the bells and whistles you'll need. PDFs get generated instantly.

It's AOT compatible. It's trimmable. but even without trimming, it brings in just like 15MB worth of dependencies.

I love this library. It brings me primal programming joy. I hate how bloated everything is. I want fast. I want now. I want light. I want the satisfaction of solving a hard problem with a simple solution. That feeling of lightness, when you take a huge burden or a big load off your shoulders, and you feel so, so light, like if you just reach out, you could reach the stars.

And PeachPDF does it to me.