121 questions from the last 30 days
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<...
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 ...
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 ...
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 ...
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)
{
...
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> ...
-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-...
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 ...
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 ...
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.
// ...
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 ...
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.
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 ...
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 ...
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 ...
-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 ...
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
{
...
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];
...
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) {...
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....
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 ...
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:...
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 ...
-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 ...
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 ...
-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 ...
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 -> ...
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 ...
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 ...
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 ...
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
...
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 ...
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:...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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&...
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 ...
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 ...
-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 ...
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 ...
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,...
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 ...
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()...
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 ...
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 "...
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 ...