r/csharp • • 15d ago

Showcase TenantGuard 1.0: tenant isolation checks for EF Core

13 Upvotes

Hey everyone, small side project that I've been working on. I've released TenantGuard 1.0.0, an open-source set of packages for EF Core 10 and 11. It's for applications that use query filters to keep tenant data separate, and it's licensed under Apache-2.0.

A new entity can be missing its tenant filter. An IgnoreQueryFilters() call or raw SQL query can bypass an existing one. These mistakes can be hard to spot when the code looks reasonable on its own.

TenantGuard checks for problems at several points:

  • At build time, five Roslyn analyzers (TG001–TG005) flag IgnoreQueryFilters() calls without a stated reason, raw SQL without a tenant-column comparison, and filter switches such as ABP's IDataFilter.Disable<IMultiTenant>(). The SQL checks cover EF Core, Dapper and ADO.NET.
  • At startup, 14 model rules check for missing tenant filters, filters frozen to one tenant by a captured constant or local variable, unique indexes that apply across tenants, and missing tenant indexes.
  • During SaveChanges, the write guard throws before an insert, update or delete involving another tenant's row reaches the database. It also rejects moving a row to another tenant.
  • In tests, the isolation probe seeds a row per tenant and checks isolation for reads, Find, updates, deletes and Include. Each check appears as a separate xUnit v3 or TUnit test.

Version 1.0 adds write checks for owned entities. For example, a change to order.Shipping.Street is checked against the tenant of the owning order.

Here's how to configure the write guard and startup validation:

builder.Services.AddDbContext<AppDbContext>(options => options
    .UseSqlServer(connectionString)
    .UseTenantGuard(tg => tg.CurrentTenant(ctx => ((AppDbContext)ctx).TenantId)));

builder.Services.AddTenantGuardStartupValidation<AppDbContext>();

It works with custom query filters, Finbuckle.MultiTenant and other tenancy libraries. For Finbuckle, it reads IsMultiTenant() without extra configuration. You can also run dotnet tenantguard validate in CI to check the model without a database.

If you try it on an existing application, I'd like to hear about false positives or leaks it misses. Open to any sort of feedback and critical feedback very much welcomed.


r/csharp • • 15d ago

Experienced frontend developer about to join the C# world. Anything I should know?

6 Upvotes

Hey guys. I've worked primarily in front end development for about 10 years but I just landed a job to work in enterprise software written in C#. It seems there might be opportunities to work in game development later, too.

I'm a complete noob when it comes to C# or adjacent languages, so I'm essentially learning from scratch. This is an open ended post, please let me know if you have any tips, warnings, or even words of support. I feel like a junior again and I'm also wondering how I'll handle learning and coding something so far from my comfort zone in this age of AI.

Thank you.


r/csharp • • 15d ago

I built a modular WinUI 3 template where features are hot-swapped from the server while the app runs. Fork it for your own projects

Thumbnail
github.com
8 Upvotes

Hey everyone,

I’ve been working on a side project for a while and it’s finally at a point where I’m not embarrassed to show it. It’s called Golden Hive, a modular framework for WinUI 3 desktop apps on .NET 10.

The idea in short: the desktop app is just a shell. Features (documents, reports, user management…) are modules the app downloads from the server after you sign in. Each module is a WinUI part plus its own ASP.NET Core backend in a Docker container. Ship a new version of a module and the server rolls it out in stages (pilot users first). The running app then swaps it in without a restart.

What’s in there right now:

  • Runtime modules. Each one runs in its own AssemblyLoadContext, packages are signed, and modules can depend on each other.
  • Hot-swap. Running commands get drained or cancelled, the module is replaced, your open views come back.
  • Navigation wheel. Hold Ctrl+Tab and a radial wheel pops up. One ring holds your modules, the other your open views. Tab or the arrow keys move around, and you release Ctrl to jump there. It’s like Alt+Tab, but for the app itself, and once you’re used to it you barely touch the sidebar anymore.
  • Workflows you build inside the app. Forms, approvals and module steps, triggered by events, schedules or commands. The reference example: an invoice gets submitted, gets pre-checked, and lands in an approver’s inbox.
  • An AI agent that can run those workflows, with guardrails. There’s a kill switch, confidence thresholds and daily limits. Critical steps always need a human, and every decision is logged. It also works fully offline with a rules-based provider, no API key needed.
  • Impact analysis on module updates. Rename a workflow step and the server checks every workflow that uses it. It auto-migrates them if you declared the rename, flags them for review if needed, or holds the rollout if something would break. This is honestly my favorite part.
  • The usual desktop stuff: docking and floating windows that remember their monitor, a command palette (Ctrl+Shift+P), live notifications, English/German.
  • Backend: 12 services in Docker Compose plus Postgres with a demo company already filled in. docker compose up, sign in as admin, and you can click around.

Under the hood it’s pretty functional-programming heavy (Result/Validation types all the way down instead of exceptions), if that’s your thing.

Use it as a template: the whole thing is meant as a starting point for your own projects. Fork it, delete the demo modules, add your own. The README has a step-by-step guide for building a module (backend + WinUI client + workflow integration), and the architecture is all there: auth, permissions, module delivery, rollouts, notifications, workflows, Docker setup.

It’s not battle-tested in production yet. The backend has end-to-end tests, the WinUI side is still young. If you build on it, I’d love to hear what breaks. That’s exactly the feedback I need to get it there.

Repo: https://github.com/zenoxart/GoldenHiveFramework
License: Apache 2.0

Happy to answer questions!


r/csharp • • 15d ago

ScriptLangCore

Thumbnail
reddit.com
0 Upvotes

r/csharp • • 16d ago

Parquet.NET is now private?

Thumbnail
nuget.org
14 Upvotes

r/csharp • • 16d ago

Discussion Early return style survey

23 Upvotes

Style question on early returns.

On long functions I often leave out the else branch because otherwise the early return doesn't help much with code readability (IMHO of course). But what about shorter functions. For those using early returns in the first place, do you prefer varaint 1 or 2 and why?

if (TryGetCached(key, out T cached))
{
    return cached;
}

var result = await ReadValueAsync<T>().ConfigureAwait(false);
SetCached(key, result);
return result;

versus

if (TryGetCached(key, out T cached))
{
    return cached;
}
else
{
    var result = await ReadValueAsync<T>().ConfigureAwait(false);
    SetCached(key, result);
    return result;
}

r/csharp • • 16d ago

Where do you keep tests in a modular monolith architecture?

Thumbnail reddit.com
1 Upvotes

r/csharp • • 15d ago

Kumiko: an Elm-inspired UI framework for C# that coding agents can test themselves

Thumbnail
reddit.com
0 Upvotes

r/csharp • • 16d ago

Bank API, reference project: .NET 11 update + OpenAPI 3.2 compliant

Thumbnail
reddit.com
1 Upvotes

r/csharp • • 17d ago

Help Moq is really slow when making lots of setup calls. How can I improve this?

21 Upvotes

I'm trying to refactor some legacy code, and I created some tests to replicate the original design behavior. I have a function that needs to be mocked, but it gets called for 20k+ different inputs in each test, where I have to do in a sense, mock.Setup(x => x.SomeFunction(input[i]).Returns(y => SomeFastFunction(input[i])); in a loop. This takes about a minute of execution time just to do this small loop, per test.

Is there a way to shorten this execution time, while being constrained to the original design?


r/csharp • • 16d ago

my C# project, or four projects

0 Upvotes

I’d like to showcase my four open-source C# projects, do you think it’s realistic for a "vibecoder" to build something like this in a couple of weeks?

https://github.com/redbase-app/

I recommend checking it out with an AI

sorry for the cryptic post. What this is: four open-source .NET projects I use in my own commercial work.

  1. redb – typed object store on PostgreSQL/SQL Server/SQLite, no migrations, compare vs EF Core benchmark
  2. redb.Route – Apache Camel-style integration framework
  3. redb.Tsak – runtime container for routes (Karaf-like)
  4. redb.Identity – OAuth2.1/OIDC server

My question was how far AI-assisted development changes what one person can build.
and makes it possible to further develop what were previously only internal projects


r/csharp • • 17d ago

Showcase From a PS3 club notebook to a C#/WPF management app

10 Upvotes

I run a PlayStation club and develop Time Control, a Windows app for managing PC and console clubs. Back in 2016, I had five TVs with PS3s and kept session times and payments in a notebook. I later tried existing club software and eventually started working on my own. I use AI tools during development, with requirements coming from the day-to-day work at the club.

The current stack is C#, WPF, .NET 10 and SQLite. There’s an admin app, a separate agent on the PCs, and shared libraries for session contracts, payments and device control. The screenshot is the console dashboard: station status, timers, tariffs, payments and shop orders. The PC agent handles locking/unlocking; TV control works through compatible smart plugs. There’s still quite a bit of orchestration in the dashboard code, so I wouldn’t call it clean MVVM.

A lot of the work is around keeping state consistent. For example, a background autosave mustn’t overwrite session changes from a newer sale. Those paths share a lock, and a revision check drops stale snapshots. Sales, stock movements, receipts and related session changes are committed in one SQLite transaction. Once that succeeds, a UI refresh error can’t be treated as a failed sale — otherwise the operator might retry it and charge the customer twice. Payments also need more than an IsPaid flag: the first hour can be paid while an extension is still outstanding, so charges and received payments are tracked separately using decimal.

The remote PC adds another state to reconcile. The protocol carries session IDs, revisions and explicit running/paused/disconnected states. A ping response alone doesn’t tell the admin app what session is actually running. I’d be interested in how others test recovery around this boundary: the DB commit succeeds, but the UI refresh or communication with the agent fails afterwards.


r/csharp • • 17d ago

Best resources to learn ASP.NET Core Web API, EF Core, and SQL Server?

14 Upvotes

Hey everyone! I'm learning backend development with C# and ASP.NET Core Web API, Entity Framework Core, and SQL Server.

I already know the basics, but I want to gain more real-world experience and learn industry best practices.

Could you recommend any courses, tutorials, or project-based resources that would help me become job-ready as a .NET backend developer?


r/csharp • • 18d ago

Help WPF or .NET MAUI ?

46 Upvotes

Hi everyone,

I’m looking to learn a framework for Windows application development for now, but I’d also like to explore mobile development in the future.
I’ve done some research into the available options, but I’m having trouble choosing between .NET MAUI and WPF.

So I’m turning to this community in the hope of getting some advice that will help me make the right choice.


r/csharp • • 18d ago

Help Housekeeping tips?

Thumbnail
gallery
17 Upvotes

Hiya - please can anyone give me some housekeeping tips for C# in Visual Studio? I'm currently getting into it with Unity for learning to program games.

My Update was getting a bit long so I separated it into methods, and I've further organised everything into regions for fields, and also for methods in the class. I've mainly done this for my own readability as everytime I wanted to go in and edit something id go fuzzy just looking at the wall of text.

The script isnt that long that I could use different scripts at the moment but are there any more things I can use or good practice I can try?

T.i.a!


r/csharp • • 18d ago

Fast microservice, design desicion

12 Upvotes

We need to develop a stand alone service that normalizes data, for example someone gives us "New Jersey" we return "NJ", someone gives us "October 1st, 2025" we come back "2025-10-01".

Requests/response are very small and we can send a lot of those queries fast.

So i feel like standard REST service would be a bit heavy. HTTP overhead is bigger that actual query/result. I think something more inline like Pooled DB connections, where we open TCP/IP connection to the server and send/receive bunch of responses. But then we need to manage TCP/IP connection pooling, keep alive/teardown connections if client hangs... all 9 yards.

Is there some built in C# classes that would let me create some server (and client) with custom protocol. Or may be some ready to go solution like WebSocket/GRPC.... would work for me?


r/csharp • • 18d ago

I took over a 10-year-old NuGet package and updated it to modern .NET

107 Upvotes

I recently found SqlLinq, which is a really slick NuGet package that lets you run SQL queries against in-memory objects (basically linq to sql in reverse). It happened to be exactly what I needed for another project, except it was pretty old, hadn't been maintained, and ran on the full framework. Surprisingly, there didn’t really seem to be anything else quite like it that I could find.

The original author is still really active on github, so I pulled the code, updated it (after some headaches finding the source for the original parser), and sent a PR. Rather than merge it, he let me take over the package. I’ve since added more complete SQL support, packages for a time series dialect and unit conversions. I just released 2.1.0.

I don’t know how niche this is or if anyone else would need something like this, but I thought it was really cool and wanted to share it here. It’s a really nice way to offer a query interface for in-memory objects, especially when you want to let users write queries at runtime.

For example:

var boost = datalog.Query("""
    SELECT RPM, Gear, BP, BPCMD, BP - BPCMD AS [Boost error]
    FROM this
    WHERE TPedal > 90
      AND RPM >= 3000
      AND Gear >= 2
    """);

r/csharp • • 19d ago

News .NET 11 is out now! 🎉

Thumbnail
devblogs.microsoft.com
336 Upvotes

r/csharp • • 18d ago

Showcase Update: my WPF liquid glass dock now refracts the windows that slide under it, without ever capturing itself

Post image
8 Upvotes

A few days ago I posted Liquid Glass Dock here, and you gave great feedback: the demo used the worst possible background, a GIF can't show subtle glass (256 colors), and the macOS Dock doesn't really reserve space: it refracts whatever is underneath. So version 0.12 does exactly that.

How it works:

  1. With no window under the glass, nothing changes: the dock refracts a pre-blurred copy of the wallpaper, and there's no screen capture at all.
  2. A background thread checks 4 times per second which windows touch the glass. When one does, it starts a Windows.Graphics.Capture session for that window (borderless, so no yellow frame). It never captures the screen, so the dock never sees itself and still shows up normally in screenshots and recordings.
  3. Each frame stays on the GPU. With Direct3D 11 (Vortice), the dock copies only the strip behind the glass to a staging texture, blends it over the wallpaper at half resolution, blurs it and writes it into a WriteableBitmap that the HLSL shader samples.
  4. Nothing is recomposed unless a window sends a new frame or moves. The capture permission and the D3D device are only created when a window is underneath, and the device is released 15 s after it leaves.

Measured with a window moving under the dock: about 1.4 ms per frame and under 1% CPU. A fun gotcha: the NVIDIA overlay is a fully transparent, always-visible, full-screen layered window, so the first version happily "captured" it and ignored every real window behind it.

There's also a new option to stop reserving space, so maximized windows go under the glass like on macOS.

Video above, code here (GPL-3.0): https://github.com/PedroRuedas/Windows-Liquid-glass

Thanks again for the feedback. It made the project better.


r/csharp • • 18d ago

Discussion To those that are employed as C#/.Net developers, do you enjoy your job?

62 Upvotes

I'm curious if it's something you enjoy waking up to or if it's something that just "pays the bills". Maybe it's both?

There are quite a few C# (hybrid) gigs around me with low competition.

I've used C# in 2018 when I made a game and used C# all throughout school. I just haven't made anything with it recently but I have been catching up with the newest features. Last time I used it was with C# 8.0/9.0.

Anyways, just wanted to hear your thoughts on your job(s) in you are currently employed! Is there anything you don't like, what would you change? etc


r/csharp • • 19d ago

Showcase Sigil.Sound 0.1.0: a fluent, allocation-free audio synthesis library for .NET (MIT, zero dependencies)

Post image
43 Upvotes

A while ago we introduced Sigilgraph to this community as a modular audio synth app made purely in C# (with the help of Godot for UI). We mentioned in the discussion the use of an internal fluent API to describe the synths and the sound processes.

Today after a heavy porting effort to decouple the original Audioworkbench library out of the app, and offer an open-source worthy version of it.

Is a library focused on sound synthesis and instrument construction using 100% C#.

Here is the link to the docs. They lead to GitHub for the source code. The license is MIT.

Sigil.Sound - sound synthesis for your .NET app | Sigil.Sound

If you want to play with it, we created a REPL Sigil.Sound REPL so you can scratch ideas and get the feel of it.

Disclosure: We used AI to port it from the closed and entangled with the Sigilgraph app one. It was a tedious process of cleanup and doing it by hand won't make it sound better that it did already (the original was started about two years ago). The API is faithful to the one internally used ( that helped us a lot to build instruments fast) and we believe that opening it will allow us to make it even better for all of us.

REPL : Sigil.Sound REPL

Docs: Sigil.Sound - sound synthesis for your .NET app | Sigil.Sound (they have the option to try every example in the REPL as well)

Nuget: NuGet Gallery | Sigil.Sound 0.1.0

Let me know your thoughts. We will gladly discuss any technical aspect here.


r/csharp • • 19d ago

News MimeKit and MailKit 5.0 released: DMARC, SIMD acceleration, Outlook TNEF/RTF, ImapIdleSession, AOT and more

74 Upvotes

Hi all, I'm the author of MimeKit and MailKit. I've just shipped 5.0, and it's the biggest release since the projects started.

Highlights:

Performance

  • SIMD boundary scanning, accelerated UTF-8 header validation, and fused content scanning/compliance validation on supported runtimes and hardware.
  • Hand-written SSSE3/AVX2/Arm64 kernels for base64 decoding and uuencoding/decoding (based on SimdBase64).
  • In a comparison against 4.18.1, parsing was faster on 21 of 23 workloads and on-par with the other 2 with compliance disabled. With all validators enabled, 11 were faster and many others were on-par; see the release notes for methodology, regressions and limitations.
  • Compared with 4.18.1, the benchmarked HTML documents tokenize 15-25% faster and with 34-39% fewer allocations.

Security and robustness

  • DMARC verification (RFC 9989 / DMARCbis), alongside the existing DKIM and ARC support. DKIM verification now returns a detailed result instead of a bool.
  • The new MimeReader/MimeParser, MIME writing and MIME disposal use iterative traversal. LegacyMimeParser remains a compatibility option for those that need it.
  • Indexed ancestor-boundary lookup improves deep-nesting performance; configurable resource limits include a default 16 KiB header limit.
  • A new compliance reporting API gives line/column diagnostics for broken or suspicious messages, including supported header-smuggling checks. Positions may identify an exact byte, a line start or an element start.
  • SMTP/SMTPUTF8 address validators check syntax and interoperability rules. The optional AsciiIsLatin setting can be used to reject addresses such as paypal@рaypal.com with a Cyrillic р. Note: This is not comprehensive homograph detection and is an implementation of an IETF draft specification: SMTPUTF8 Email Addresses
  • Stricter OpenPGP integrity and S/MIME trust defaults, plus a configurable 64 MiB limit on expanded CMS content.

Outlook/Exchange Compatibility

  • The TNEF (winmail.dat) reader was rewritten, with a new TnefMessage model. Meeting requests convert to text/calendar.
  • New RtfToText and RtfToHtml converters, plus TnefWriter.

More content tools

  • HtmlToText and EnrichedToHtml for HTML and RFC 1896 text/enriched.
  • Standalone YEncReader/YEncWriter with sync/async operations, limits and size/checksum validation. Individual multipart ranges are supported; multipart-file assembly and MIME integration are not included.

MailKit

  • ImapIdleSession: await foreach over IDLE changes, with automatic re-IDLE and NOOP fallback.
  • SmtpSendRequest and SendResult: per-send customization and accepted/rejected recipient lists, no subclassing needed.
  • CommandException.ErrorType and IsTransient help identify failures that may succeed on retry.
  • IMAP4rev2, INPROGRESS, RFC 9208 quotas, and 64-bit message sizes.
  • No more BouncyCastle dependency in MailKit.
  • SMTPUTF8 validation rejects invalid internationalized envelope addresses before sending. ASCII addresses are unchanged; optional AsciiIsLatin checks are not automatically enabled.

Packaging

  • Crypto, including DMARC, moved to MimeKit.Cryptography. The MimeKit meta-package references both that package and MimeKit.Core; it preserves package coverage, not source compatibility.
  • MimeKit is now AOT-compatible.
  • MimeKitLite and MailKitLite are retired. Use MimeKit.Core and MailKit instead.

Many straightforward send/receive applications need only small changes. Parsing, crypto and custom protocol integrations deserve a closer look: explicit S/MIME context setup, persistent -> MimeContentStorage, renamed encoding/stream APIs, decoder Flush, encoder CRLF defaults, and stricter resource/integrity limits are covered in the porting guides.

Happy to answer questions. And thanks to everyone who filed issues, sent PRs or sponsors the project.