340,756 questions
1
vote
1
answer
67
views
Does reading one stream that is a copy of another stream affect the original stream position
I'm checking the file signature of an IFormFile and I'm curious if I can avoid resetting to the beginning of the stream after my check is done. I intend to dispose the copy of the original stream and ...
1
vote
2
answers
117
views
How to fake a second function call using FakeItEasy?
I have a class that looks like this:
public int DoWork(int value)
{
return value + GetDataFromDB();
}
public int GetDataFromDB()
{
return 10;
}
In the real world the second function goes ...
1733
votes
30
answers
542k
views
What is the difference between const and readonly in C#?
What is the difference between const and readonly in C#?
When would you use one over the other?
4
votes
2
answers
101
views
Why does dotnet restore on a .sln ignore `DownloadContentFiles` tasks in .csproj projects?
I have an .sln referencing a single .csproj. Inside the .csproj I download static dependencies into ASP.NET's wwwroot:
<Target Name="DownloadContentFiles" BeforeTargets="Restore&...
2440
votes
15
answers
293k
views
Should 'using' directives be inside or outside the namespace in C#?
I have been running StyleCop over some C# code, and it keeps reporting that my using directives should be inside the namespace.
Is there a technical reason for putting the using directives inside ...
9
votes
2
answers
2k
views
Where is the documentation for the '.slnx' solution format? [closed]
All I can find from Microsoft is two blog posts:
"Introducing support for SLNX, a new, simpler solution file format
in the .NET CLI" dated March 13th, 2025, says that it is a preview ...
1
vote
0
answers
98
views
PdfSharpCore - fields that are completed are not being shown their content in Adobe Acrobat but work on Firefox, Edge, etc
As the title says, I have this class which is based on PdfSharpCore.
I have a PDF file which is AcroForm (doesn't seem to be XFA, although I'm not 100% as I don't have much experience with PDFs - but ...
1204
votes
30
answers
1.2m
views
Deserialize JSON into C# dynamic object? [duplicate]
Is there a way to deserialize JSON content into a C# dynamic type? It would be nice to skip creating a bunch of classes in order to use the DataContractJsonSerializer.
1288
votes
15
answers
2.3m
views
How do I turn a C# object into a JSON string in .NET?
I have classes like these:
class MyDate
{
int year, month, day;
}
class Lad
{
string firstName;
string lastName;
MyDate dateOfBirth;
}
And I would like to turn a Lad object into a ...
1145
votes
28
answers
1.3m
views
How can I get the application's path in a .NET console application?
How do I find the application's path in a console application?
In Windows Forms, I can use Application.StartupPath to find the current path, but this doesn't seem to be available in a console ...
2
votes
3
answers
2k
views
Supports 16kb memory page size issue in .Net MAUI
On Play Console in App bundle detail I get this:
Does not support 16 KB
Hide detail
Learn more
Libraries that do not support 16 KB:
base/lib/arm64-v8a/libHarfBuzzSharp.so
base/lib/arm64-v8a/...
3
votes
0
answers
145
views
C# service doesn't run on Windows Server, but runs on Windows 10
I'm trying to build a background service with autostart in the background.
Core logic in console app executing from OnStart, however after several failures at debugging root cause - modified code by ...
220
votes
9
answers
193k
views
Open .net framework 4.5 project in VS 2022. Is there any workaround?
Is there anyway to open and work on .net framework 4.5 project in visual studio 2022.
May be problem is not with VS2022 but as .net framework 4.5 developer pack is not available any more .. my project ...
0
votes
1
answer
102
views
.NET Framework 4.8-targeted application is working fine in a machine which only have .NET Framework 4.7.2
I have an exe which is written using .NET Framework 4.8.
I have the following line in the vbproj file of the exe.
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.8&...
1
vote
2
answers
254
views
How to dynamically create a C# class that inherits from a generic base class referencing itself (T : Base<T>)?
I am trying to dynamically generate a C# class T at runtime using Reflection.Emit (or other dynamic type creation techniques). The challenge is that the base class is a generic type U<T> that is ...
145
votes
11
answers
109k
views
A fatal error occurred. The folder [/usr/share/dotnet/host/fxr] does not exist
I can't access dotnet after an update. Reinstalling dotnet and vscode didn't help.
On Ubuntu 22.04, running dotnet --info produces the output:
A fatal error occurred. The folder [/usr/share/dotnet/...
734
votes
47
answers
569k
views
MetadataException: Unable to load the specified metadata resource
All of a sudden I keep getting a MetadataException on instantiating my generated ObjectContext class. The connection string in App.Config looks correct - hasn't changed since last it worked - and I've ...
0
votes
0
answers
71
views
How to return data annotations error message in one string?
I'm using data annotations from System.ComponentModel.DataAnnotations in my ASP.NET project. I get an error message where you can describe the requirements such as "Name is required" and etc....
770
votes
36
answers
399k
views
Implementing INotifyPropertyChanged - does a better way exist?
Microsoft should have implemented something snappy for INotifyPropertyChanged, like in the automatic properties, just specify {get; set; notify;}
I think it makes a lot of sense to do it. Or are there ...
657
votes
43
answers
845k
views
Associating enums with strings in C#
I know the following is not possible because the Enumeration's type has to be an int
enum GroupTypes
{
TheGroup = "OEM",
TheOtherGroup = "CMB"
}
From my database I get a field with ...
0
votes
1
answer
129
views
Black screen and error sound in Windows 11 Pro kiosk mode
I have an C# .NET app that I tried packaging both as appxbundle and msix to use as a Kiosk application. Both works when launched normally but fails to load when run after setting up assigned access. I ...
884
votes
32
answers
922k
views
How to delete all files and folders in a directory?
Using C#, how can I delete all files and folders from a directory, but still keep the root directory?
1
vote
0
answers
170
views
Enum mapping hell PostgreSQL => EF Core 9
I am creating a brand new project to prototype an ASP.NET Core 9 Web API backend with PostgreSQL using the latest Entity Framework Core 9 and Npsgsql 9. Everything was going well until I hit a table ...
3
votes
0
answers
92
views
How to synchronize blob names stored in the database with the actual blobs in Azure Blob Storage
Current problem: when we store files in Azure Blob Storage, we create a folder per entity (company/user).
The name of the folder includes:
Entity ID (required to guarantee that the folder name will ...
0
votes
1
answer
67
views
System.Net.Http.MutlipartFormDataContent error in client running in .NET Framework 4.8 when connecting to Apache Tomcat server
This is my .NET Http Client minimal reproducible example, which connects to a server running on a CNC machine edge device and uploads a local JSON configuration file:
using System;
using System.IO;
...