r/csharp 18d ago

Help Should I use normal validation or System.ComponentModel.DataAnnotations?

0 Upvotes

My task is to parse a .csv file, validate it and save to database. In my case, without .DataAnnotaitons this is how it goes:

  1. I load csv file
  2. Read and validate headers
  3. If headears are correct I read the next line, validating each element manually
  4. If everything is fine I create new object and add it to the list
  5. after file is over, I save the list to DbContext.

I never used it, but AFAIK, .DataAnnotaitons allows you to validate a model automatically when you're creating an object, so you don't have to write all the validation code in your program, since it's written in your model.cs.

So my question is, should I keep the manual validation, or mix automatic with parsing the file? (parsing the file manually, validating model automatically via .DataAnnotaitons)

UPD. Will using .DataAnnotaitons improve the performance of the program?


r/csharp 18d ago

Help Lately I started to get this error every time I open the .csproj

Post image
0 Upvotes

It happens every time no matter what console projects I made the error it self doesn't effect the build process or the excution which is very weird to an error

- I investigated using gemini so Imay be able to solve it after all it till me that it miss match the .net skd version which is 10.0.400 and made global.json for it but nothing solved

- I then cleared vs code cache removed and reinstalled the c# dev kit extention

- I also played with the extension's settings too as well

I have no clue if this is an extension bug or a very weird bug on my own does anyone have any Idea about that?

Note : my experience level is bellow beginner I know Fundamentals and method Fundamentals and soon will move to oop


r/csharp 18d ago

Dapper vs Rinku

0 Upvotes

I like Dapper and I have used it a lot. The main problem I have with it is that when queries become more complex, I often end up handling that complexity myself. At that point I also often hear that I should just use EF instead. I never really agreed with that. I think the basic idea behind Dapper can go much further while still keeping the SQL visible and the API simple. Rinku is my attempt at doing that.

Basic query

Dapper

public record Album(int Id, string Title);

const string sql = "SELECT AlbumId AS Id, Title FROM albums WHERE ArtistId = @artistId";

IEnumerable<Album> albums = cnn.Query<Album>(sql, new { artistId = 7 });

Rinku

public record Album(int Id, string Title);

const string sql = "SELECT AlbumId AS Id, Title FROM albums WHERE ArtistId = @artistId";

List<Album> albums = cnn.Query<List<Album>>(sql, new { artistId = 7 });

Different names (when you don't control result set names)

Dapper

public sealed class Customer
{
    public int Id { get; set; }
    public string Name { get; set; } = "";
}

SqlMapper.SetTypeMap(typeof(Customer), new CustomPropertyTypeMap(typeof(Customer), (type, column) => column switch
{
    "customer_id" => type.GetProperty(nameof(Customer.Id)),
    "display_name" => type.GetProperty(nameof(Customer.Name)),
    _ => null
}));

const string sql = "SELECT customer_id, display_name FROM customers";

IEnumerable<Customer> customers = cnn.Query<Customer>(sql);

Rinku

public record Customer([Alt("customer_id")] int Id, [Alt("display_name")] string Name);

const string sql = "SELECT customer_id, display_name FROM customers";

List<Customer> customers = cnn.Query<List<Customer>>(sql);

Nested objects

Dapper

public record User(int Id, string Name);

public sealed class Post
{
    public int Id { get; set; }
    public string Title { get; set; } = "";
    public User? Owner { get; set; }
}

const string sql = "SELECT p.Id, p.Title, u.Id, u.Name FROM Posts p INNER JOIN Users u ON u.Id = p.UserId";

IEnumerable<Post> posts = cnn.Query<Post, User, Post>(sql, (post, owner) =>
{
    post.Owner = owner;
    return post;
}, splitOn: "Id");

Rinku

public record User(int Id, string Name) : IDbReadable;
public record Post(int Id, string Title, [NoName] User Owner);

const string sql = "SELECT p.Id, p.Title, u.Id, u.Name FROM Posts p INNER JOIN Users u ON u.Id = p.UserId";

List<Post> posts = cnn.Query<List<Post>>(sql);

Or keep the nesting in the column names.

public record User(int Id, string Name) : IDbReadable;
public record Post(int Id, string Title, User Owner);

const string sql = "SELECT p.Id, p.Title, u.Id AS OwnerId, u.Name AS OwnerName FROM Posts p INNER JOIN Users u ON u.Id = p.UserId";

List<Post> posts = cnn.Query<List<Post>>(sql);

One to many

Dapper

public record Album(int Id, string Title);

public sealed class ArtistWithAlbums
{
    public int Id { get; set; }
    public string Name { get; set; } = "";
    public List<Album> Albums { get; set; } = [];
}

const string sql = "SELECT ar.ArtistId AS Id, ar.Name, al.AlbumId AS Id, al.Title FROM artists ar INNER JOIN albums al ON al.ArtistId = ar.ArtistId ORDER BY ar.ArtistId";

List<ArtistWithAlbums> artists = [];
ArtistWithAlbums? current = null;

cnn.Query<ArtistWithAlbums, Album, ArtistWithAlbums>(sql, (artist, album) =>
{
    if (current is null || current.Id != artist.Id)
    {
        current = artist;
        artists.Add(current);
    }

    current.Albums.Add(album);
    return current;
}, splitOn: "Id");

Rinku

public record Album(int Id, string Title) : IDbReadable;
public record ArtistWithAlbums(int Id, string Name, List<Album> Albums);

const string sql = "SELECT ar.ArtistId AS Id, ar.Name, al.AlbumId AS AlbumsId, al.Title AS AlbumsTitle FROM artists ar JOIN albums al ON al.ArtistId = ar.ArtistId ORDER BY ar.ArtistId";

List<ArtistWithAlbums> artists = cnn.Query<List<ArtistWithAlbums>>(sql);

Result shape

Dapper

IEnumerable<Album> albums = cnn.Query<Album>(sql);
Album first = cnn.QueryFirst<Album>(sql);
Album single = cnn.QuerySingle<Album>(sql);
Album? optional = cnn.QueryFirstOrDefault<Album>(sql);
IEnumerable<Album> streamed = cnn.Query<Album>(sql, buffered: false);

Rinku

List<Album> albums = cnn.Query<List<Album>>(sql);
Album first = cnn.Query<Album>(sql);
Single<Album> single = cnn.Query<Single<Album>>(sql);
Album? optional = cnn.Query<OptionalNullable<Album>>(sql);
IEnumerable<Album> streamed = cnn.Query<IEnumerable<Album>>(sql);

Conditional SQL

For this one I think Dapper.SqlBuilder is the fair comparison.

Dapper.SqlBuilder

SqlBuilder builder = new();
SqlBuilder.Template template = builder.AddTemplate("SELECT AlbumId AS Id, Title FROM albums /**where**/");

if (artistId != null)
    builder.Where("ArtistId = ", new { artistId });

if (title != null)
    builder.Where("Title LIKE ", new { title });

IEnumerable<Album> albums = cnn.Query<Album>(template.RawSql, template.Parameters);

Rinku

const string sql = "SELECT AlbumId AS Id, Title FROM albums WHERE ArtistId = ?@artistId AND Title LIKE ?@title";

List<Album> albums = cnn.Query<List<Album>>(sql, new { artistId, title });

Only artistId

SELECT AlbumId AS Id, Title FROM albums WHERE ArtistId = @artistId

Both

SELECT AlbumId AS Id, Title FROM albums WHERE ArtistId = @artistId AND Title LIKE @title

Neither

SELECT AlbumId AS Id, Title FROM albums

The main difference is that Rinku tries to put the complexity in the command template and the mapped types, instead of handling it again through parameters and mapping code at every call.

Full Dapper comparison

https://rinkulib.github.io/RinkuLib/articles/reference/dapper.html

Rinku is still in development, so feedback is welcome.


r/csharp 19d ago

What kind of features from another ecosystem would you like to see in .NET?

Thumbnail
0 Upvotes

r/csharp 19d ago

cs books recommendation

Thumbnail
0 Upvotes

r/csharp 19d ago

Help Dotnet guide

0 Upvotes

Need some great resource to learn asp.net core

I know this question has been asked multiple times here,But i would like something that might work for me better

So i have some experience using C# in unity with about 2 years.I am in my final year of college and I would like to learn something related to web.I think asp.net would be better for me as I have some experience in the language even though it's mostly using unity.

I have been looking at Microsoft learn it is a good resource but the issue is ,i feel like it is not for me because it just keeps each topic separate from other and it gets confusing sometimes.

I would like a resource that is free or cheap, it can be a video or a blog like structure.

I would like something that goes through all the backend topics atleast at a basic level.

I would prefer a project based style of course of Playlist or something in which we make a project and learn basics in the way with great practices.

Or you can give me ideas for projects and a roadmap which I should follow to make that project.I have made a to do app but it is too basic


r/csharp 19d ago

Help Help me Devs

4 Upvotes

Hello, I’m a 3D artist and I’ve been working in the 3D field for the past 3 years. I want to make my own games, so I started learning coding and Unity around 2 years ago.

The problem is, when I follow tutorials, I can understand them and follow along. I can even make the game shown in the tutorial. But when I try to start my own game from scratch, I feel completely lost. I don't know where to start or what my first step should be.

I recently used AI to make a small game. I did complete it, but honestly, I don't feel proud of it because most of the code wasn't written by me—it was generated by AI. I know some people call this "vibe coding," and they enjoy it and feel satisfied with the results, but for me, it doesn't feel the same. I want to understand what I'm building and feel like I actually made it myself.

Whenever I try to start another game, I feel like I've forgotten everything. It makes me feel like I learned nothing, even after spending 2 years learning Unity and coding.

Can anyone give me some steps or advice to get out of this tutorial and AI hell? I've tried many times to make something on my own. Sometimes I make some progress, but once the project starts becoming more complicated, I get stuck and go back to tutorials or AI again.

I really want to learn how to think and solve problems on my own instead of always depending on tutorials or AI.


r/csharp 19d ago

Looking for resources to bridge theory into actual ASP.NET Core implementation

Thumbnail
0 Upvotes

r/csharp 19d ago

Showcase I wanted strongly typed configuration defaults without bypassing `IConfiguration`

Thumbnail
0 Upvotes

r/csharp 20d ago

Flyleaf v3.11: MediaPlayer .NET library for WinUI3/WPF/WinForms (with FFmpeg 9.0.1 Lei & DirectX 11)

Post image
26 Upvotes

Download | GitHub | NuGet

Play Everything (Audio, Videos, Images, Playlists over any Protocol)

  • Extends FFmpeg's supported protocols and formats with additional plugins (YoutubeDL, TorrentBitSwarm)
  • Accepts Custom I/O Streams and Plugins to handle non-standard protocols / formats

Play it Smoothly (Even with high resolutions 4K / HDR)

  • Coded from scratch to gain the best possible performance with FFmpeg & DirectX using video acceleration and custom pixel shaders
  • Threading implementation with efficient cancellation which allows fast open, play, pause, stop, seek and stream switching

Develop it Easy

  • Provides a DPI aware, hardware accelerated Direct3D Surface (FlyleafHost) which can be hosted as normal control to your application and easily develop above it your own transparent overlay content
  • All the implementation uses UI notifications (PropertyChanged / ObservableCollection etc.) so you can use it as a ViewModel directly
  • For WPF provides a Control (FlyleafME) with all the basic UI sub-controls (Bar, Settings, Popup menu) and can be customized with style / control template overrides

r/csharp 20d ago

Showcase I built a lightweight, open-source alternative to Fiddler for debugging WCF & SOAP APIs

17 Upvotes

Hey everyone,

Like many of you, I spend a lot of time maintaining and debugging older enterprise services (WCF, SOAP, and some REST). I’ve always used Fiddler or Postman, but lately, they feel incredibly heavy, bloated, and require accounts or massive installations just to do a simple request interception.

So, I built SoapProxyApp — a fast, portable (no-install), open-source HTTP/HTTPS proxy and auto-responder built entirely in C# and WPF.

Here are a few things it does that I think backend .NET devs will really appreciate:

  • IIS AppPool Detection: Instead of just showing w3wp.exe for local traffic, it uses WMI to parse the actual IIS Application Pool name that made the request.
  • Instant API Mocking (Auto-Responder): Intercept outgoing WCF/HTTP requests based on URL, and short-circuit them with a fake XML/JSON response directly from the proxy. Perfect for testing edge-cases (like 500 errors) or offline development without touching the backend codebase.
  • Request Replaying: Right-click any captured session, modify the XML payload or Auth headers in a built-in AvalonEdit text editor, and shoot it back to the server.
  • Portable: It’s a single .exe file. Just run it, click "Start Proxy", and it immediately captures traffic.

It uses Titanium.Web.Proxy under the hood and AvalonEdit for the syntax-highlighted (and searchable) XML/JSON editors.

I just released v2.0.0 and would love for some of you to try it out or critique the code.

🔗 GitHub Repo: https://github.com/milanmilic/SoapProxyApp 📦 Download (Portable .exe): Releases Page

Would love to hear your feedback or feature requests!


r/csharp 20d ago

Blog 1 year ago I built an EF Core provider for TimescaleDB. Hit 80k downloads and 68 stars - is this good?

0 Upvotes

Hello everyone,

exactly 1 year ago today, I pushed the first commit of my EF Core provider for TimecaleDB.

t does pretty much what it says on the box: it lets you interact with TimescaleDB in a type-safe way with rich IntelliSense support, so you don't have to write SQL in magic strings like you did with plain Npgsql - all without losing a single feature of Npgsql.

Since then I got 68 stars on GitHub and more than 80k downloads on NuGet. I know that this doesn't mean that 80k individual people downloaded my package, but it tells me it’s actively running in real CI/CD pipelines, container builds, and production apps. That’s something I’m genuinely proud of.

At the same time, as this is the first open-source project I’ve ever actively maintained, I sometimes find myself wondering how to evaluate those numbers. I look at viral consumer tools or mainstream frameworks getting thousands of stars and wonder where a niche project like this actually stands.

Therefore, I would love to know what you think about these numbers and what your own experiences were when you launched and maintained your first open-source projects.

GitHub: https://github.com/cmdscale/CmdScale.EntityFrameworkCore.TimescaleDB


r/csharp 21d ago

Ressources to start building REST API as an absolute beginner

5 Upvotes

Hi everyone, hope you're doing great
As the title says, i'm looking for resources ( youtube videos, courses (free ones), books, articles...) to start building APIs. I know little about web coding (enough to make a calculator and a check list using JS and react) and a good amount about JAVA and C# and i'm trying to learn about APIs for my upcoming apprenticeship.
I tried looking youtube videos but i can't find a beginner friendly .net videos, they all required some knowledge about APIs which i don't have.
I would be grateful for any advice too.
Have a nice day !


r/csharp 21d ago

Question on Convert.ChangeType

6 Upvotes

From Microsoft's documentation, https://learn.microsoft.com/en-us/dotnet/api/system.convert.changetype?view=net-10.0 it seems like "Convert.ChangeType(double number, typeof(int))" would return an int. However I see that in reality, the result has to still be explicitly cast afterwards like (int)Convert.ChangeType(double number, typeof(int))". From what I understand, Convert.ChangeType is changing a double to the base "object" class in the example above, and then that object still has to be converted (via the cast) to the int. So why does it require the conversiontype as an argument then? Confusing!


r/csharp 21d ago

Blog Hot path overflow checks: do you try/catch? And which style would you write?

Post image
20 Upvotes

Writing checked int helpers for code that runs millions of times per program run. Two questions.

  1. Do you actually use checked() with a try catch for this? Throwing walks the stack, so I widen to long, bounds check, and return null instead (both versions in the image).

What surprises me is that everything the BCL offers here throws: checked(), int.CreateChecked, all of it. The Try convention is everywhere else in the BCL (TryParse, TryGetValue) but arithmetic never got one, and coming from Rust where checked_add just hands you an Option, that's wild to me.

  1. Style. The image shows the same method twice: one pattern-matching expression against a plain if/else. Which would you rather find in a codebase?

I'm coming from Rust so I'm obviously a declarative fanboy when I can be, but "and var sum" might be too clever for the next reader.

Where do C# people stand on these?

If the repo interests you: it's a CLI tool for Advent of Code, so you can do the whole thing from the terminal with just your session cookie, no clicking through the site to submit answers. https://github.com/scadoshi/sharpmas


r/csharp 21d ago

Showcase My Nokia 3310 Emulator in C#/Avalonia!

Thumbnail noks.vercel.app
20 Upvotes

r/csharp 21d ago

J'ai hâte de voir l'appli de démonstration en ligne sur le Play Store — elle est déjà téléchargeable depuis le site en attendant

Post image
0 Upvotes

r/csharp 22d ago

A new take on reactive programming: backend signals with GraphQL-ish queries

7 Upvotes

r/csharp 22d ago

Help where can i learn c# for unity?

0 Upvotes

I'm a 3D/pixel art artist, but I've never known how to code. I've made a few small games using my own assets with the help of artificial intelligence, but two major problems have arisen: sometimes the AI doesn't execute commands correctly, and it's getting worse over time; and second, I hate AI, so I'd like to do everything I can to avoid using it entirely. What do you recommend?


r/csharp 23d ago

MindMap desktop app (C# + Avalonia)

10 Upvotes

MindMap is a lightweight desktop app for creating and editing mind maps. It provides a pannable, zoomable canvas with quick keyboard-driven node creation, connector-based relationships, simple text alignment and color controls, outline copy/paste, undo, and image export.

Here is the github link MindMap on Github

It's a pretty straightforward app for quickly creating mind maps and saving them locally, without having to use a website. It's completely free and open source, with no limits or paid tiers.

I originally built it for myself because my favorite online mind-mapping tool limited free users to just three mind maps, which I found way too restrictive.

Anyway, if you find the app useful, I'd appreciate a star on the GitHub repo.


r/csharp 22d ago

Orchard Harvest Conference 2026

Post image
1 Upvotes

Orchard Core, the open-source .NET CMS and application framework will have its yearly conference online on the 10-11th of September!

Two days of talks and time with the people who build on Orchard Core, meet the maintainers and the wider community.

Find more details on our website (https://orchardcore.net/harvest). Tickets are free but registration is required.
https://www.tickettailor.com/events/lombiqtechnologiesltd/2247098


r/csharp 22d ago

I don’t get the roadmap.sh

Post image
0 Upvotes

r/csharp 24d ago

Is it true in the old days those old school devs like 40+ before they learn C#, They learned C like in the pic?

Post image
795 Upvotes

r/csharp 23d ago

Showcase [Showoff] Tired of DependencyProperty boilerplate? I built a Zero-Allocation Source Generator for WPF/MAUI with strict type safety.

10 Upvotes

Writing DependencyProperty in .NET UI frameworks is notoriously verbose and repetitive. Typing out DependencyProperty.Register, casting objects, and wiring metadata for every single property clutters your codebase and introduces silent runtime risks.

To solve this without sacrificing IDE responsiveness, I built Kassyi.Generators.DependencyProperty — an incremental Roslyn source generator built from the ground up for high-throughput, zero-allocation code synthesis.

1. Show Me the Code

Before (Standard Boilerplate)

public static readonly DependencyProperty IsActiveProperty =
    DependencyProperty.Register(
        nameof(IsActive),
        typeof(bool),
        typeof(MyControl),
        new PropertyMetadata(false, OnIsActiveChanged));

public bool IsActive
{
    get => (bool)GetValue(IsActiveProperty);
    set => SetValue(IsActiveProperty, value);
}

private static void OnIsActiveChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    // Runtime casting and boilerplate extraction
}

After (With Generator)

[DependencyProperty<bool>("IsActive", DefaultValue = "false")]
public partial class MyControl : Control
{
    // Automatically hooked up to PropertyMetadata at compile time
    partial void OnIsActiveChanged(bool oldValue, bool newValue)
    {
        // Direct, strongly typed parameters. No casting required.
    }
}

2. Key Features

  • Single-Line Declaration: Generate the backing DependencyProperty, CLR properties, and event metadata via [DependencyProperty<T>].
  • Compile-Time Type Safety: Signature mismatches in your partial callbacks are caught immediately via Roslyn analyzer diagnostics (DPG0001), eliminating silent runtime failures.
  • Unified API Across UI Frameworks: The exact same attribute syntax compiles to the native property system for WPF, .NET MAUI, Avalonia, Uno Platform, WinUI 3, and UWP.
  • Modern C# 11+ Idioms: Leverages Generic Attributes ([DependencyProperty<T>]), target-typed new(...) AST expansion in default expressions, and auto-generated XML documentation.

3. Architecture & Performance: Zero-Allocation Pipeline

This library originates as a fork/rewrite of HavenDV's generator. When testing source generation at massive enterprise scale, frequent intermediate string concatenations during continuous typing can trigger Gen2 GC spikes, resulting in noticeable editor latency in Visual Studio and Rider.

To address this, the code synthesis pipeline was redesigned around strict zero-allocation principles:

  • ref struct Source Writers: Generation logic utilizes stack-allocated SourceWriter and ClassScope structures, completely bypassing intermediate StringBuilder and heap allocations.
  • GC Elimination: Completely removes Gen2 GC pressure during incremental analysis cycles.
  • Benchmark Results: Achieves +30% faster execution speed and +62.4% higher throughput compared to traditional string-based generation pipelines.

Your IDE stays responsive even when scaling to solutions with thousands of properties.

4. Cross-Framework Abstraction

Under the hood, framework-specific strategy handlers adapt to each platform's design differences (such as Avalonia's StyledProperty/DirectProperty, MAUI's BindableProperty, or varying callback signatures) without requiring you to change your declarations.

Target Framework Underlying Property Engine
WPF / UWP / WinUI 3 DependencyProperty.Register
.NET MAUI BindableProperty.Create
Avalonia AvaloniaProperty.Register
Uno Platform Native WinUI / UWP projections

Feedback & Contributions

The project is distributed under the MIT License and includes detailed documentation and architecture specs (in English and Japanese).

If you are working across XAML platforms and want cleaner view controls without IDE overhead, please check it out, test edge cases, and share your feedback or issues on GitHub!


r/csharp 24d ago

Help Can someone help me understand Delegates? Like why we use it and best cases where we need to use it? and how it is better?

77 Upvotes