r/csharp • • 1h ago

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

• 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 • • 17h ago

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

Post image
0 Upvotes

r/csharp • • 23h 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 • • 23h 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 • • 1h ago

CsCheck 5.0 - .NET 11 and native AOT ready

Thumbnail
• Upvotes

r/csharp • • 14h ago

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

22 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!