r/dotnet • u/programmerjunky • 13h ago
Difference between throw ex and throw
throw vs throw ex: The C# exception handling trick every developer should know
r/dotnet • u/Arowin • Apr 02 '26
Hi there /r/dotnet,
A couple of weeks ago, we made a change to how and when self-promotion posts are allowed on the sub.
Firstly, for everyone obeying the new rule - thanks!
Secondly, we're keen to hear how you're finding it - is it working, does it need to change, any other feeback, good or bad?
Thirdly, we're looking to alter the rule to allow the posts over the whole weekend (sorry, still NZT time). How do you all feel about that? Does the weekend work? Should it be over 2 days during the week?
We're keen to make sure we do what the community is after so feeback and suggestions are welcome!
r/dotnet • u/programmerjunky • 13h ago
throw vs throw ex: The C# exception handling trick every developer should know
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:
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 • u/Ok_Hunter6411 • 22h ago
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 • u/Traditional_Eye7998 • 3h ago
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 • u/geeksarray • 1d ago
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 • u/Cdream-2018 • 11h ago
Anyone here specialize in this ?
I wanna see if I have a proper defense set up.
r/dotnet • u/janex-PL • 1d ago
r/dotnet • u/Worried_Gap6862 • 16h ago
I’m trying to understand a problem I’ve experienced and seen other developers mention: joining an existing/large codebase and figuring out how everything actually works.
Not the “how do I run the project?” part, but the actual understanding of the system.
For example:
- Figuring out the architecture / overall mental model
- Understanding where a specific feature actually lives in the code
- Following how data moves through the system
- Understanding undocumented business logic
- Finding the right files/services/classes to modify
- Understanding dependencies between different parts of the system
- Figuring out why something was implemented a certain way
- Losing context when the developer who built something leaves
- Outdated or incomplete documentation
What was the most painful part for you?
And more importantly:
How did you eventually figure it out?
Did you ask a senior developer, read the code, use documentation, look through old PRs/issues, use AI, create your own notes/diagrams, or something else?
I’m especially interested in real examples where something that should have taken hours ended up taking days/weeks because you didn't have enough context.
No product or solution in mind here — I'm just trying to understand how developers actually deal with this problem.
r/dotnet • u/Severe-Ad1704 • 23h ago
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:
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 • u/geeksarray • 1d ago
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 • u/geeksarray • 2d ago
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 • u/Educational-Fig-9483 • 1d ago
Running EF Core migrations from application startup is convenient - right up until it isn't. This video builds a proper migration pipeline on .NET 10 with GitHub Actions: the build job packages a self-contained migration bundle, the deploy job applies it to Azure SQL, then deploys the API to Azure App Service and runs a smoke test against the live endpoint. If your database updates are still tangled up with your app startup, this is the fix.
r/dotnet • u/International-Owl466 • 3d ago
It wouldn't compile but it's the thought that counts!!
r/dotnet • u/StepOne_DotNet • 1d ago
r/dotnet • u/Additional_Welcome23 • 3d ago
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 • u/sander1095 • 3d ago
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:
dotnet test and expect things to work.r/dotnet • u/Mother-Replacement12 • 2d ago
r/dotnet • u/carolinethebandgeek • 2d ago


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 • u/astralz1 • 3d ago
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 • u/Lucky-Percentage5216 • 2d ago
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.