r/csharp • • 2h ago

Help C# On Linux

7 Upvotes

Hi guys i need some help. so i just started my third year in cs and completely switched to linux and yesterday i started my class on Programming with paradigms and my professor is using visual studio to create Winforms .net projects or something like this i am quite new to C# world and .net especially and i don't know what to do where to write the code cause he does all those sorts of visual gui handling adding buttoms and stuff and i just downloaded rider but it does not have those gui stuff and also is quite weird to move around file structure even if we forget that code based window creation so if there is any alternative or something that will help please let me know if not it does not concern me to use rider and get used to it but if there is something that i can follow my professor better please let me know

Thanks in advance

Wannabe Systems Administrator


r/csharp • • 5h ago

Help How do you artificially trigger all the execution paths in a code ?

0 Upvotes

By installing Microsoft.AspNetCore.Identity and System.ComponentModel.DataAnnotations, I believe you are able to compile the following —nearly— self-contained code:

using Microsoft.AspNetCore.Identity;
using System.ComponentModel.DataAnnotations;
namespace PlayGround
{

    public class SignupViewModel
    {



        [Required]
        [DataType(DataType.Text)]
        [Display(Name = "Name")]
        public string? Name { get; set; }

        [Required]
        [RegularExpression("^
\\+
?(\\d{1,3})?[-.\\s]?(
\\(
?\\d{3}
\\)
?[-.\\s]?)?(\\d[-.\\s]?){6,9}\\d$|(^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+
\\.
[A-Za-z]{2,}$)", ErrorMessage = "Please enter a valid email address or phone number")]
        [Display(Name = "Email or phone number")]
        public string? EmailOrPhoneNumber { get; set; }


        [Required]
        [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string? Password { get; set; }


        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "Confirm password")]
        [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
        public string? ConfirmPassword { get; set; }



    }
    public record RegistrationResult(bool IsSucceeded, List<string> Errors);

    public class ApplicationUser : IdentityUser
    {

    }
    public interface IAccount
    {
        public Task<RegistrationResult> RegisterUser(SignupViewModel SignupInput);
    }
    public class UserAccount : IAccount
    {
        private readonly IUserStore<ApplicationUser> _userStore;
        private readonly UserManager<ApplicationUser> _userManager;
        public UserAccount(IUserStore<ApplicationUser> userStore,
            UserManager<ApplicationUser> userManager)

        {
            _userManager = userManager;
            _userStore = userStore;
        }


        // HOW TO TEST THE `RegisterUser` METHOD ALONE WITHOUT RUNNING THE WHOLE  APPLICATION ?
        // I WANT TO TRIGGER ALL THE PATHES OF THE `RegisterUser` METHOD TO VERIFY THAT EACH PATH IS TRIGGERED WHEN IT IS NEEDED.
        public async Task<RegistrationResult> RegisterUser(SignupViewModel SignupInput)
        {
            // PATH 1
            var validationContext = new ValidationContext(SignupInput);
            var results = new List<ValidationResult>();
            bool valid = Validator.TryValidateObject(SignupInput, validationContext, results, validateAllProperties: true);
            if (!valid)
            {
                // PATH 2
                return new RegistrationResult(false, ["The sent data is not valid"]);
            }


            ApplicationUser user = new ApplicationUser();
            await _userStore.SetUserNameAsync(user, SignupInput.Name, CancellationToken.None);

            if (!(_userManager.SupportsUserEmail))
            {
                //PATH 3
                throw new NotSupportedException("user manager does not support user email");
            }

            var _emailStore = (IUserEmailStore<ApplicationUser>)_userStore;
            await _emailStore.SetEmailAsync(user, SignupInput.EmailOrPhoneNumber, CancellationToken.None);
            var result = await _userManager.CreateAsync(user, SignupInput.Password);
            List<IdentityError> identityErrors = result.Errors.ToList();

            if (identityErrors.Count != 0)
            {
                //PATH 4
                List<string> errorsStrings = new List<string>();

                foreach (IdentityError identityError in identityErrors)
                {
                    errorsStrings.Add(identityError.Description);
                }

                return new RegistrationResult(false, errorsStrings);



            }

            await _userManager.AddToRoleAsync(user, "Normal-User");
            return new RegistrationResult(true, []);

        }

    }

}

This code is a part of bigger application for sure, to test that method, I run the whole application:

 dotnet watch run --launch-profile https

I'm forced to do that because the input to the RegisterUser is provided by the browser, but I will not be able to trigger all the paths inside the method if I passed the data to the method using it.

Is there a way to test this method without running the whole application so that I can provide whatever data I want to the method by bypassing the client-side and the server-side validation in order to artificially trigger all the possible paths of execution ?

An applied example would be appreciated.

EDIT :

I come across the term Unit testing a lot, I'm not sure if this is what I need.


r/csharp • • 5h ago

Is it normal to not remember Syntax

Thumbnail
0 Upvotes

r/csharp • • 5h ago

JetPack WPF Theme (kind of like MahApps Metro)

0 Upvotes

I'm working on a packaged version of the good old 2010 Silverlight theme "JetPack".

I had Claude have a good look at how MahApps Metro is structured and had it construct a JetPack theme bundle along with documentation for it.

A lot of useful usercontrols that lacked in the Silverlight theme has been added, along with Mica effect, DataGrid (similar to Telerik RadGrid), SearchCombobox (similar to RadComboBox) and more.

Anyways - feedback is appreciated :)

Repo : https://github.com/Montago/JetPackTheme

Documentation : https://montago.github.io/JetPackTheme/

Nuget : https://www.nuget.org/packages/JetPack.Wpf/


r/csharp • • 7h ago

DocuTrust.NET: validate uploads by magic bytes (security update, looking for testers)

0 Upvotes

DocuTrust.NET is a small .NET 8 library that checks an upload's magic bytes against the type you expect. A PNG renamed to report.pdf fails.

I just did a security pass on it. It now checks the client file name too, rejects ZIP/OLE files over 100 MB before parsing, and keeps file names and paths out of error messages. I also updated a dependency that was pulling in a vulnerable OpenMcdf.

For now it only identifies file types. It doesn't scan for macros or scripts

 dotnet add package DocuTrust.NET

https://github.com/saa-999/DocuTrust.NET

If you try it, I'd like to know what breaks.


r/csharp • • 8h ago

CsCheck 5.0 - .NET 11 and native AOT ready

Thumbnail
5 Upvotes

r/csharp • • 20h ago

Help Confused about how default method arguments work underneath the hood in C# (CS1736)

24 Upvotes

So I recently came across CS1736 while writing some code. For example, the following method code results in a compile-time error:

public static void ErrorMethod(int[] a = new int[0]{}) {}

I’d never come across this error before strangely enough. When I read the MSFT docs about what causes it, I see the following explanation:

A default parameter value is evaluated upon the invocation of the method. What a value may be when the method is eventually invoked cannot be pre-determined at declaration-time unless that value is constant at compile-time.

What’s confusing me is why the compiler needs the arguments to be compile-time constants to be able to initialize them with default values, especially since they are only evaluated when the method is called during runtime. Wouldn’t the compiler in this case already know what I’m initializing the array as? Wouldn’t this make more sense as a runtime error if you initialize with some problematic value?

Also I’d like to confirm, when they say “compile-time constant” in the docs, is that just a different way to refer to regular “Constants”? Or is this referring to something else?

Thanks!


r/csharp • • 23h ago

I built Magpie, a self-hosted media discovery and automation app in C#

Post image
0 Upvotes

r/csharp • • 1d ago

Which programming language should I learn?

0 Upvotes

I am currently working in a company which use Asp.net web forms (2002), in 2026 hardly any one uses that. Should I focus on learning node.js in free time or focus on ASP.NET web forms


r/csharp • • 1d ago

Discussion Why do all conventions do newline brackets

0 Upvotes
class Something : EntireCodebase
{
  ...
};

struct Something
{
  ...
};

void Something(int something)
{
  ...
}

I'm really disturbed, why


r/csharp • • 1d ago

Help What is your level of knowledge in SQL? How much is required to learn about SQL?

11 Upvotes

r/csharp • • 1d ago

Help Studying hard, but lagging behind—Advice needed for a beginner learning Unity/C#

1 Upvotes

Hello again! I'm writing to say hi. I'm currently learning Unity and C# at an academy. I only use AI to get hints when I'm stuck on exercise problems or to review what I've learned. However, when solving practice problems or doing hands-on tasks at the academy... there are quite a few beginners and non-CS majors including myself, but I feel like my skills aren't improving compared to the amount of time I'm putting in. Even today, I had to keep looking at my textbook and still ended up with an incomplete solution after taking a really long time... haha.

I have ADHD and was never really good at studying back in my school days. In fact, programming and Unity are so much fun that I'm studying harder now than ever before in my life. But I feel like my brain just isn't up to speed—I lag far behind others in how fast they understand and memorize things. Is it okay for me to keep going without getting impatient? I'm worried that by the time the academy program ends, I still won't be able to code on my own.


r/csharp • • 1d ago

Help Beginner learning C#/.NET: should I continue or switch because of AI? Hi everyone, I'm a beginner learning C#/.NET and I want to build apps. With AI getting so good at writing code (and hiring for juniors slowing down), I'm worried my time might be wasted. 1. Should I continue with C#/.NET

0 Upvotes

​

Hi everyone,

I'm a beginner learning C#/.NET and I want to build apps. With AI getting so good at writing code (and hiring for juniors slowing down), I'm worried my time might be wasted.

  1. Should I continue with C#/.NET, or switch to something else (Python, Flutter, React Native)?

  2. Which direction would you recommend for a beginner today?

Any honest advice would help a lot. Thank you!


r/csharp • • 1d ago

Free C# Learning Resources for a not-quite beginner

1 Upvotes

As the title says, I need to refresh my C# after letting my skills deteriorate over a few months. I'm not quite a beginner - my knowledge largely coming from having done the full Unity Learn course - but a lot of those skills have been left to fester. Whatever resources would ideally be free or bare minimum cheap. Any help would be appreciated!


r/csharp • • 1d ago

Help What’s the best way to learn c#?

5 Upvotes

I don’t know how to do anything with c# but I won’t to learn what’s the best way? Is it YouTube, online classes, learn to code websites or something else


r/csharp • • 2d ago

ResXLocalization 2.0: .resx files based localization for Avalonia and WPF, now with ICU MessageFormat support

2 Upvotes

Hi, I have just released version 2.0.0 of ResXLocalization, my localization library for WPF and Avalonia (MIT-licensed).

In essence:

  1. Create your .resx files.

  2. Install ResXLocalization.Avalonia or ResXLocalization.WPF.

  3. Let it generate the typed resource keys (source generator) and use them in XAML and code:

    <TextBlock Text="{l:Localize {x:Static res:SettingsViewKeys.SaveSetting}}" />

    this.SaveButton.Content = Localizer.Current.Get(SettingsViewKeys.SaveSetting);

  4. And live switch the language/culture:

    Localizer.Current.CurrentCulture = new CultureInfo("de-DE");

Typed keys mean you can reference resources like objects and get compile time checking.
This avoids having typos in resource names go unnoticed.

When you change Localizer.Current.CurrentCulture it updates all localization bindings in place. If you assign a string directly in code as above, you need to call Get again after changing the culture.

The biggest new feature of V2 is the optional ICU MessageFormat support (thank you livonium for the feature request that sparked the work on V2!):
For something like “1 file deleted” / “5 files deleted”, you can use a plural rule in your resource text:

{Count, plural, one {# file deleted} other {# files deleted}}

(You need to install the NuGet package ResXLocalization.MessageFormat and call Localizer.Current.UseMessageFormat() at startup for this to work)

Then just bind the count like this:

<TextBlock>
  <TextBlock.Text>
    <l:Localize Key="{x:Static res:AppStringsKeys.FilesDeleted}">
      <l:Argument Name="Count" Value="{Binding DeletedCount}" />
    </l:Localize>
  </TextBlock.Text>
</TextBlock>

The text block is automatically updated when either the count or the language changes.
Of course you can also bind multiple values to a localized text/message.

Each translation can use its language/culture plural rules.
The ICU message format support is opt-in. If you don't use it, the default formatter (based on string.Format) is used.

A few other changes in this release:

  • Typed keys now finally work also without a .Designer.cs file.
  • Formatting arguments are now placed via <Argument> children of the Localize/LocalizeEnum markup extension, which replaces the old Arg0…Arg8 attached properties, so arguments now also work in styles and templates.
  • Resource keys are bindable, so the view model can dynamically decide which resource to use.
  • You can change the preview language (for VS XAML Designer/Rider XAML previewer) with DesignTime.Culture. However, ResXLocalization does not work correctly in Rider's WPF previewer due to a number (there are quite a few) of bugs in it. JetBrains has really made quite a few unfortunate design decisions for their previewer. I tried to work around them as far as possible, but it's nowhere near perfect.

The library supports .NET 8 and later with Avalonia (12+) or WPF.
For Avalonia it is completely native AOT compatible and trim safe (for WPF, native AOT is not supported, because WPF doesn't have support for it).

If you are upgrading from V1, please read the migration guide, because there are quite a few breaking changes to make it all work.

The repository has runnable sample apps (both for Avalonia and WPF):
https://github.com/rent-a-developer/ResXLocalization

AI attribution:
I used AI, mainly Claude, for brainstorming, planning, experiments, and parts of the implementation. It helped me save a great deal of time finding good solutions for a couple of quirks of Avalonia and (especially) WPF and the source generator’s MSBuild integration. I reviewed the generated code and I use ResXLocalization in my own projects, so I would not settle for some half-baked vibe coded garbage. Of course, if you don't like projects where AI is involved, then just ignore this project and that's fine too.

I hope this helps someone with the localization of their app(s)!

If you find this library useful I would appreciate a star on GitHub.

Of course feature request and (reasonable) criticism is welcome too.


r/csharp • • 2d ago

[Open Source] Created a simple tool to fix broken Windows Update policies and reliably install .NET Framework 3.5 (dev on .NET 4.7.2)

Thumbnail
2 Upvotes

r/csharp • • 2d ago

Discussion Can I learn computer architecture and operating systems with C#?

18 Upvotes

I'm a full-stack developer, and I want to learn more about computer architecture and operating systems to become a better developer and understand what's happening under the hood.Can I learn these things with C#, or should I learn C first? Does the language even matter that much?What would you recommend?


r/csharp • • 2d ago

Help Is C# worth learning in the AI era? (Web dev background looking to future-proof)

0 Upvotes

Hey everyone,

I’ve been building things for the web using JavaScript, TypeScript, and PHP (Mostly). Up to now, it’s been a solid stack with a great job market. But with how fast things are shifting, especially with AI tooling changing the landscape. I’m trying to future-proof my skills and can't entirely predict where things are heading.

I keep hearing about C# and .NET as a robust enterprise choice, but I’m wondering how it fits into the current AI-driven era.

  • For those of you working in C#/.NET right now, how has the job market and day-to-day work changed with AI code assistants?
  • Is learning C# a smart pivot or addition for a web dev trying to stay relevant, or should I double down elsewhere?

Curious to hear your thoughts and experiences!


r/csharp • • 2d ago

About codebase conventions, who is actually right and who is wrong here?

Post image
124 Upvotes

Let's say you're a Technical Founder like Mark Zuckerberg or Bill Gates. You have a CS degree worked as mid level developer.

You've written some code (as show in the pic) and added comments to remind yourself and other developers what the code does, so nobody forgets in the future.

Now, you have a Senior Developer on your team who worships Uncle Bob's Clean Code principles like a cult!

she reviews your PR and reject it, saying

"Good code should be self-explanatory. The code itself should explain what it's doing.

Anyone should be able to look at it on the first time and understand it right away.

So go back and remove those comments. They're not clean! God damn it!"

--

What would you do in this situation?

Would you trust the senior dev and delete the comments because they have more experience than you, even though you're the founder and have less development experience than they do?

Ps. We have to move fast


r/csharp • • 2d ago

Help Anyone here built measurement/monitoring software in C#?

13 Upvotes

Hey, has anyone here worked on industrial measurement or monitoring software with C#?

I'm currently looking into rebuilding an older monitoring solution from scratch and still figuring out the right architecture.

We're talking different measurement devices, continuous data streams (up to 1k samples/sec per channel), older Windows PCs with 4 GB RAM, and ideally something that can run reliably for months.

What I'm a bit unsure about is the data integrity side of things, especially crash recovery, audit trails, and GMP requirements.

I'm leaning towards C#, probably with SQLite, but not sure if I'm overlooking something.

Would be really interested to hear from anyone who's built something similar. What would you do differently today?


r/csharp • • 2d ago

Request for wisdom regarding VS when learning C#

0 Upvotes

Dear C# devs,

My main language is python, but due to work I got exposed to C#, and would greatly benefit from learning it. I already am mostly familiar with the language's syntax due to some C++ exposure, but I am far from familiar with many C# concepts and the visual studio editor. In summary, I am a beginner to the language, but not to programming. I can write simple programs, but heavily lack the knowledge of C#'s environment such as projects, solutions, their respective settings, how to link DLLs and set up tests within visual studio.

I strongly feel that visual studio code is abstract (albeit efficient) in the way it performs those tasks and like it prevents me from learning what is actually going on. All I am learning is that I should click seemingly arbitrary submenu A, then B and then C. Voila, you now can run tests. Why? I have no idea.

To actually get an understanding of C#'s environment I therefore am considering omitting VS entirely and instead develop through the CLI. Hopefully, that way I actually learn what the .NET framework is, and how to work with it, how to set up projects, solutions, go through the compilation processes,and more.

I just wanted to ask the true C# veterans among us whether this proposed learning approach is a good idea, or whether I am missing something.

All constructive feedback is greatly appreciated.
Good night everyone!


r/csharp • • 3d ago

What is the most anticipated feature of the language that is not included in C#15 for you?

7 Upvotes

It 's coming up very soon .NET 11 and C#15, all the innovations are already known (at least in C#). Which of the non-products or proposals would you like to see in the next versions?


r/csharp • • 3d ago

Discussion Is it justified to create an interface in this specific case ?

13 Upvotes

An Admin panel is to be made.

There is a piece of code that paginates users ; instead of showing 50 users in one page in the admin panel, the users are split across 5 pages, so each page shows 10 users.

I recognized that I should also paginate products.

should I make IPaginator<T> interface with two concrete implementations, ProductsPaginator<Product> and UsersPaginator<User> ?

If that is wrong, then what do you suggest ?

EDIT:

I think that is wrong, because maybe the implementation of the pagination logic is the same in both cases, what is different is the input; in the first implementation, the input is all the products , for the second implementation the input is all the users, so what is actually different is the input, not the implementation, therefore it is better to make Paginator<T> ?

Also there is another question:

When the user clicks on the page number 1, should the data come from the database or from a cache ?

How do you normally design the pagination feature ?

Second edit :

I realized that I neither need interface nor a class, I can just use the skip and take methods that LINQ offers.


r/csharp • • 3d ago

NET MVC multilingual website: JSON vs RESX vs separate Razor views

Thumbnail
0 Upvotes