Skip to main content
The 2025 Developer Survey results are in. Explore insights into technology and tools, careers, community and more. View results.
Filter by
Sorted by
Tagged with
3 votes
4 answers
102 views

Populating generic object that is known to be an array at runtime

I have a generic method that returns type T (generic). In the method, if T is an array, I want to create and populate this array with data and return. I've gotten to the point where I have a List<...
GafferMan2112's user avatar
1 vote
2 answers
131 views

Is there a tidy way to declare a variable that I need to assign to inside a lock()? [closed]

I have a line of code: var dates = League.AllGames.Select(g => g.Time.Date).Distinct().ToList(); But I need to lock the League object before I do LINQ on AllGames -- League has several lists that ...
Doug Burbidge's user avatar
3 votes
2 answers
97 views

Does UDP receive messages in a queue-like format?

I have two programs set up to mimic two machines that will be communicating using UDP (I know TCP sounds better in this situation, but the manufacturer for one of the machines made it such that ...
winter-raptor0411's user avatar
1 vote
1 answer
114 views

Can I send Console.WriteLine() output to a control on a Winform within the same app

I have a .NET console app that does some processing - reading .TXT files, and generating new ones. Throughout the code are instances of Console.WriteLine(...) that outputs various progressing info to ...
Adrian K's user avatar
  • 10.3k
3 votes
1 answer
145 views

Why FileSystemInfo.Refresh doesn't update timestamps after file deletion

There's a few posts here explaining the caching behavior of FileSystemInfo and the derived FileInfo class such as this one . But when the following code is run, static void Main(string[] args) { ...
Dave's user avatar
  • 153
1 vote
2 answers
75 views

Is there a way to ignore specific subfolders when using DirectoryInfo.EnumerateFiles without manual recursion?

I'm using the following code to get all files of given extensions inside a folder with it's respective subfolders. string path = "C:\\FolderA\\FolderB\\FolderC\\FolderD"; List<string> ...
vmHernandes's user avatar
-1 votes
1 answer
81 views

Regex character range excluding one character

Is there any straight-forward way to create a regex pattern in .NET that includes all characters in a range except one? I want to find any lowercase letter except 's'. Currently I'm using "[a-r t-...
Simon Elms's user avatar
  • 20.1k
0 votes
2 answers
102 views

If I specify the capacity of a dictionary through the constructor, should I use a prime? [closed]

I am initializing a fairly large dictionary in C#. I have benchmarked the speed of building the dictionary with the capacity and without. It is (as expected) significantly faster (and uses ...
FluidMechanics Potential Flows's user avatar
1 vote
1 answer
98 views

How to find and read files with malformed names in .NET?

I have deliberately create a file with a malformed name: printf '\xC3\x28malformed_name.txt' | xargs touch Verifying it exists: ls ''$'\303''(malformed_name.txt' .NET can also see the file: open ...
sdgfsdh's user avatar
  • 37.6k
0 votes
1 answer
140 views

.NET DataViewGrid displays both date and time in a column unless it's midnight then you only see the date

I'm displaying the date and time in a DataViewGrid column and that works as expected unless it's midnight and then it's only displaying the date. I want it to display the time no matter what. // ...
Christian Blackburn's user avatar
0 votes
0 answers
173 views

Access denied while deleting in .NET

I'm trying to figure out why I'm getting an "Access denied" error while deleting a Directory via System.IO.Directory.Delete(Path.Combine(path, folderName), true); These folders are being ...
prabhaat's user avatar
1 vote
2 answers
45 views

How to enable logging in C# SignedXML (System.Security.Cryptography.Xml)

How can one receive more verbose logs from SignedXML class in C#? I see in SourceLink that there are links to SignedXmlDebugLog class, but I don't know how I can read these logs.
Andrzej Kaczor's user avatar
0 votes
1 answer
93 views

Does the dynamic keyword box the value types? [closed]

This project is ASP.NET MVC Framework 4.8 with Entity Framework 6 and uses: dynamic GetSystemSetting(string paramCode, string paramType) It contains Int, Float, Bool, String, and Guid values. It is ...
Guhan Srinivasan's user avatar
1 vote
2 answers
84 views

Combining multiple unknown queries using Union

I have an Entity Framework Core statement where I need to create a union of multiple selects. The number of selects is variable. I would like to do something like this, but it is not working: public ...
Joel's user avatar
  • 131
2 votes
1 answer
70 views

PageOverlayColor not working for Maui CommunityToolkit Popup

I am in the process of updating a .net maui project to .net9 and have not been successful implementing the new popup rewrite using CommunityToolkit 12.1.0. The background around the popup except for ...
Carr O'Connor's user avatar
-1 votes
1 answer
108 views

Is there ever utility in assigning an IDbParameter's `.Value` to null after comparing its .Value to null with `is`?

I've inherited some very old code that has a section that reduces to this: if (idbparam.Value is null) { idbparam.Value = null; } idbparam is an IDbDataParameter. It appears that the outcomes of ...
ruffin's user avatar
  • 17.6k
3 votes
1 answer
70 views

Does C# .NET AES GenerateKey (RandomNumberGenerator) truly use /dev/urandom on Linux

Generating a key and I have tried to understand how GenerateKey gets random in Linux. Example: using System; using System.Security.Cryptography; namespace AesEncryption { class Program { ...
Pea Kay See Es's user avatar
0 votes
1 answer
94 views

How to get sub list in C# [duplicate]

I have a problem! I need to get sub list like sub array using start index and and index string[] stringArray = ["2", "a", "dummy-data"]; var subArray = stringArray[0..1]; ...
TheMakarik's user avatar
2 votes
3 answers
123 views

Why add ConfigureAwait(false) again when the library code already use ConfigureAwait(false)? [duplicate]

below is an example from CLR via C# book: private sealed class MyWpfWindow : Window { public MyWpfWindow() { Title = "WPF Window"; } protected override void OnActivated(EventArgs e) {...
user25521292's user avatar
0 votes
1 answer
118 views

Why is `JArray.ToObject<List<T>>` faster than `JArray.ToObject<T[]>`

We are trying to micro-optimise some parts of our production code and I was expecting that using Arrays would generally be better than Lists in .NET, and most of the times, my benchmarks indicate that....
FluidMechanics Potential Flows's user avatar
2 votes
1 answer
135 views

Where does an exception with an empty call stack come from?

I'm debugging an older Winforms application running on .NET 4.8 which is using some COM components. Occasionally, it throws this exception and then crashes: System.IO.FileNotFoundException: 'Could ...
Tymur Gubayev's user avatar
0 votes
2 answers
91 views

System.InvalidOperationException : Sequence contains more than one element for DotNet Testcontainer

Error Log: Standard Output Messages: [testcontainers.org 00:00:03.98] Reuse is an experimental feature. For more information, visit: https://dotnet.testcontainers.org/api/resource_reuse/ -> warning:...
Raisus's user avatar
  • 177
1 vote
1 answer
97 views

Compiling issues with roslyn

I want to dynamically compile model classes for my EF Core app. For that I use Roslyn, but I'm facing problems when trying to compile. One of my model classes looks like this: using head.de; using ...
DevEV's user avatar
  • 23
-4 votes
0 answers
160 views

Populate a DataTable row with the primary key after an Insert into a SQL Server table

I have a DataTable in C# with a primary key column that is using negative numbers to auto increment. When I update the back end, I cannot figure out how to get the primary key from the database into ...
Mike's user avatar
  • 11
0 votes
0 answers
129 views

.NET Sporadic FormatException: Cannot deserialize a 'String' from BsonType 'ObjectId'

Since upgrading to .NET 6 to .NET 8, we are getting very unusual and sporadic behaviour from MongoDB (driver?). Every couple of days (sometimes weeks) the driver would start throwing the following ...
bgajic's user avatar
  • 63
-1 votes
3 answers
97 views

What is the difference between these two methods of returning new instance value?

The first method is the normal code execution. The second method is the one that is commented out. Isn't returning an instance of a class from a newly created standalone service provider the same as ...
Bob Bobber's user avatar
0 votes
0 answers
95 views

AppServices `AppUnavailable` when packaging as MSIX - Minimal reproducible example available*

I have the following solution structure: / └── MyApp.Package.wapproj -> WAP project which packages MyApp.Win in MSIX └── MyApp.Win.csproj -> ...
Miguel's user avatar
  • 161
1 vote
0 answers
93 views

Storage quota errors when trying to upload files via Google Drive API

I'm trying to upload a small sample CSV file up to my personal google drive via a Service Account, but it keeps failing. I've created a folder in my personal Drive, and shared it with my Service ...
DSW's user avatar
  • 11
0 votes
1 answer
86 views

Why can't Entity Framework soft-delete via SaveChanges? (and an alternative solution)

I want to implement "soft delete" in my application, meaning that instead of physically removing records from the database, I set an IsDeleted flag to true. My expectation is to intercept ...
Tetik's user avatar
  • 1
3 votes
1 answer
75 views

C# Native AoT - How to get pointer to Managed class to pass as parameter to Com Object

I have implemented INetworkListManagerEvents interface to get network connectivity state changes as a C# class. In my project, the INetworkListManagerEvents is code generated via CsWin32 source ...
Guezt's user avatar
  • 157
1 vote
0 answers
192 views

Can not trigger DpiChanged event in .NET Framework 4.72 VB Winforms app

I'm trying to add the DpiChanged event in a VB Winforms application, but the event is not raised. Please check the gif animation in the link below for detailed movement https://imgur.com/a/hYot4HP ...
RYA234's user avatar
  • 11
1 vote
1 answer
70 views

ASP.NET Core OpenAPI - how to add request examples?

I'm trying to add example request bodies to my OpenAPI spec in an ASP.NET Core 9 Minimal API application. I've added an example using OpenApiObject as shown here: using Microsoft.OpenApi.Any; using ...
dhrm's user avatar
  • 15k
2 votes
1 answer
74 views

TransactionScope lost on making TestInitialize async

For a project I'm working on, I'd like to insert testdata before every test and then rollback the transaction for the next test to start with a clean slate. The skeleton code below works fine for that:...
Caramiriel's user avatar
  • 7,365
1 vote
1 answer
79 views

How can I create tcp client for simple chat system in .NET?

I am trying to create a chat system using tcp. I have 3 apps, 1 tcp listener and 2 tcp clients. I want to create a simple chatting system but I can't figure it out. I have created a server that ...
Saul4Goodman's user avatar
1 vote
2 answers
81 views

TCPListener returns error when it disconnects

When the TCP client disconnects, the TCP listener is giving an error; 2 clients just send random messages every second. When I close one client, the listener is giving an error and because of that the ...
Saul4Goodman's user avatar
0 votes
2 answers
84 views

Centralized assembly versioning by using Directory.Build.props file

I want to achieve an automatic versioning of all my assemblies in my solution on building the solution for deployment. First I've created a configuration 'Deploy' in my solution (based on ...
Michael Hartmann's user avatar
1 vote
0 answers
82 views

C# Memory not released unless GC.Collect() is called after Redis data fetch [duplicate]

I’m observing steadily increasing RAM usage in this service, even though the method just fetches data from Redis and does not retain it. The memory usage only drops when I call GC.Collect() manually ...
Zerr Ax's user avatar
  • 11
1 vote
0 answers
71 views

System.ObjectDisposedException: Request has finished and HttpContext disposed when making requests in Task.WhenAll

I'm trying to create a test where I can simulate multiple users simultaneously passing requests through my custom middleware. I was hoping that I could create multiple simultaneous requests using ...
roscoelee's user avatar
  • 311
1 vote
0 answers
90 views

Application developed in .NET 4.8 is working fine on a machine with only .NET 4.7 is installed. Is that expected?

I have a .NET application which is developed using .NET 4.5. Now this is migrated to .NET 4.8. It is a Windows application. I have a web service also targetting .NET 4.8. When I deploy the web service ...
Jyothish Bhaskaran's user avatar
1 vote
0 answers
72 views

When adding nuget packages, why do dependencies also get referenced in the parent project?

I have a project that I'm sharing on nuget. However, this project itself contains references to more nuget packages, which I've added as dependencies in the nuspec. <metadata> <version&...
komodosp's user avatar
  • 3,676
2 votes
0 answers
73 views

.NET Visa connection to instrument fails [closed]

I am trying to communicate with an power supply using VISA communication. I want to use the IviFoundation.Visa nuget package. I always get an error that the instrument is not found when trying to open ...
justsomedude100's user avatar
2 votes
0 answers
81 views

Does closure variable capture introduce thread safety risks due to field implementation?

Follow-up to: Detailed Explanation of Variable Capture in Closures Given that captured variables are implemented as fields in compiler-generated classes (as explained in the referenced answer), does ...
Jasper's user avatar
  • 39
-4 votes
0 answers
63 views

TestContainer for MailDev Docker API responded with status code=Conflict, response={"message":"container xxxx is not running"} [closed]

I have already looked into this issue from other questions on this site: Docker API respond with status code conflict, container xxxxxx is not running - related to MsSqlBuilder TestContainers ...
Raisus's user avatar
  • 177
1 vote
0 answers
79 views

System.Windows.Forms's WebBrowser is garbage collected differently in .NET Framework and Core

I'm trying to migrate our application from .NET Framework to .NET Core. In one of our tests, an object of type ZWebBrowser : System.Windows.Forms.WebBrowser is not garbage collected correctly, due to ...
VEvergarden's user avatar
1 vote
1 answer
66 views

Order an EF Core query from DB1 based on property from DB2

I need to run an EF Core query on a DB1 that can be ordered by a property from DB2. The problem is: I have a DB1 with a table of Users. My Users contain references of entities from DB2 using their ids,...
Vicente Monteiro's user avatar
0 votes
0 answers
64 views

Dotnet Aspire > Failed to debug this project because no SQL Server has been installed on the local machine

I'm trying to setup program.cs in AppHost project with all resources (SQL, API) but unable to spin up SQL project I want my SQL project to run without any dependency of my SQL credentials. Instead it ...
AbdulQASDET's user avatar
1 vote
1 answer
54 views

Can I reuse the EF Core DbContext within a retry strategy execution that uses a transaction?

I'm reading the docs for connection resiliency and transactions, which has the following example: await strategy.ExecuteAsync( async () => { using var context = new BloggingContext()...
Hazza's user avatar
  • 6,603
1 vote
0 answers
67 views

I can't send email from .NET application using Google SMTP client, application passwords

I have Google workspace, created for my mail application passwords and used the code as password in my .NET application. This worked for me in test application without Google workspace, from private ...
Majkel's user avatar
  • 63
1 vote
1 answer
66 views

How to make "Go to definition" work for default Blazor components in Visual Studio 2022?

How do I make options from Peak Definition through Go To Declaration work for default Blazor components, like NavLink or PageTitle? I want to see the source code of these components. I've tried "...
MarioPL98's user avatar
0 votes
3 answers
55 views

Implementing Android foreground service for device timer to update UI every minute

I am creating time tracking app in .net MAUI. And I want to run timer continues even app minimized so for that I am creating Android foreground service in MAUI. And it is work also but my issue is ...
Prakash Menaria's user avatar