As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [.net]

.NET is a software framework supporting a multi-language paradigm and supporting language interoperability. .NET applications are executed in a virtual machine (CLR) which provides a few important services: security, memory management and exception handling.

Filter by
Sorted by
Tagged with
3 votes
1 answer
137 views

Threadsafe Non-Overlapping Timer

I was working on a project recently, where I needed to process some tasks periodically, but the execution of those tasks could not overlap with one another. ...
rickmanalexander's user avatar
0 votes
0 answers
51 views

Service Locactor with accessing service safely for .Net DI

I have implemented a service locator, but I am unsure if the services (instances) obtained from it can guarantee the security of the accessed or manipulated data. In some classes where services cannot ...
YUu's user avatar
  • 23
1 vote
0 answers
26 views

Thread-safe key-value cache with expiration

I need my cache hold items to be accessible by key. The items should disappear after a configured time period. I do not need the lifetime of items to be exactly as configured. All I need is to make ...
C-F's user avatar
  • 111
0 votes
0 answers
44 views

Code structure for 3rd party API calls

The Problem: I need to create a HttpService (Interface + Implementation) within an application that will be responsible for communicating with an external API service. There are three types of data ...
Vedran Knezevic's user avatar
2 votes
1 answer
123 views

My own ThrowHelper extension methods

I really like ArgumentNullException.ThrowIf(...) and ArgumentException.ThrowIfNullOrEmpty(...) and there are upcoming ones in ....
nop's user avatar
  • 709
0 votes
1 answer
297 views

Copy object without reference using reflection

Recently I was in need of a method to copy an object and pass it to a method which alters the data. Since a class is passed by reference this would alter the class in the caller which I don't want. So,...
Roe's user avatar
  • 121
1 vote
0 answers
490 views

Optimizing a EF Core "upsert" operation

I'm trying to "optimize" the command below. In other words, to make it suit my needs using best practices. I found a lot of posts regarding the "upsert" operation and there were a ...
nop's user avatar
  • 709
0 votes
0 answers
192 views

Extend the login timeout in a ASP NET 7 application

My ASP Core web application was recently upgraded from NET6 to NET7. Almost zero problems except one, which still puzzles me. With the "old" NET6 version, once an user log then app in (...
Mario Vernari's user avatar
1 vote
1 answer
85 views

Request-response model over sockets/websockets

This is a request-response model over sockets/websockets (like HTTP) where you technically match request id to response id and return the response. In addition to that, there is timeout in case that ...
nop's user avatar
  • 709
2 votes
1 answer
97 views

Saving entity containing complex jsonb column with validation and comparision

I've been a .NET Developer for almost 4 years. I'm stronly learning and trying using design patterns and following SOLID principles for 3 months right now (I know - a little late, but better late ...
KJanek's user avatar
  • 23
2 votes
1 answer
214 views

Serilog logging extension methods

I've been using this extension in almost all of my projects. What's your opinion? Do you think there is something else to add or to be improved? The idea is to ignore all default ASP.NET messages that ...
nop's user avatar
  • 709
0 votes
0 answers
39 views

Modified PoC for BlogEngine.NET CMS (CVE-2019-6714)

This is a modified exploit proof of concept targeting the BlogEngine.NET content management system (CVE-2019-6714) for the .NET framework. I modified it (from Cobb 2019) to execute payloads via ...
Aleksey's user avatar
  • 101
0 votes
0 answers
100 views

Is this a good implementation of Dependency Injection using MVVM without any nuget packages?

So I've been looking into dependency injection for WPF while still using an MVVM pattern. And something that's been incredibly difficult to wrap my head around was, how to create a navigation service ...
Jess Chan's user avatar
  • 101
1 vote
0 answers
58 views

A service that downloads the whole trade history off an exchange and involves Redis cache

This service is pulling off the whole trade history for the Binance accounts. More precisely, it's a wrapper around https://binance-docs.github.io/apidocs/spot/en/#all-orders-user_data. Since their ...
nop's user avatar
  • 709
3 votes
1 answer
668 views

Find closest value in a big list

There are solutions e.g. list.OrderBy(item => Math.Abs(number - item)).First() or ...
nop's user avatar
  • 709
3 votes
1 answer
566 views

Use a static field for cache an authentication token in .NET API

I have a .NET 6 web API that does some requests to another third party API, this API has a token that expires after a few hours, so I want to cache this token and reuse in the requests. Here how I ...
Vanderlei Morais's user avatar
2 votes
2 answers
133 views

Decrypt incoming HTTP request headers

During each HTTP request incoming from my Angular front-end I send encrypted pair of access & refresh token. On the back-end ASP.NET web APIs are used. The way I decrypt them currently is by ...
Andrеw's user avatar
  • 21
0 votes
0 answers
139 views

Creating a simple HTTP GET endpoint that pulls off products from a mocked API and returns filtered subset of products

I was given a task assessment for the interview of a company and here is the code that I shared with them https://github.com/Hulkstance/poq. I wonder what suggestions you would write to me. ...
nop's user avatar
  • 709
-1 votes
2 answers
135 views

C# .NET 6, implementation of concurrent throttling tool

I'd like to seek advice on my implementation of rate controlling or throtting tool which implemented by C#.NET 6. correctness of implementation performance issue or any improvement can be done. <...
Timeless's user avatar
1 vote
1 answer
265 views

RabbitMQ ConnectionFactory wrapper

This is a wrapper around RabbitMQ.Client's ConnectionFactory. Here is the simplest Producer/Consumer RabbitMQ example https://github.com/delaneybrian/jumpstartCS-...
nop's user avatar
  • 709
2 votes
2 answers
496 views

Extension methods to modify an async Task's type from Task<IEnumerable<T>> to Task<List<T>>

I've written a lot of (await SomeTask).AsList(); in my project, and it's kind of annoying to keep wrapping it. To fix this I've written a little extension method on ...
Joost00719's user avatar
0 votes
0 answers
1k views

Unit testing / TDD MediatR Queries and Validators

I would like to get a code review for the following code. It's meant to filter mocked products. I used to not like writing tests, but some time ago I realized how great TDD is. Not only it makes the ...
nop's user avatar
  • 709
3 votes
5 answers
615 views

Struct that parses full name into first name, middle name, last name and suffix

The struct below parses full name into first name, middle name, last name and suffix. Perhaps Builder pattern is more appropriate here? I remember there was a principle referring to the number of ...
nop's user avatar
  • 709
1 vote
1 answer
160 views

Creating complex object step by step

Builder pattern separates object construction from its representation I have to generate username and password for the Account class. Since this operation is a bit ...
nop's user avatar
  • 709
1 vote
0 answers
85 views

TPL Dataflow ActionBlock that doesn't allow the same data to exist in the buffer

I'm implementing a queue to update leaderboards when score data changes in the background. Updating the leaderboard is a relatively expensive operation, so if we say "Update leaderboard 5" ...
Mike Christensen's user avatar
2 votes
2 answers
76 views

Project sequence to multiple sequences using LINQ (or extension methods)

I'm creating a method that expands a sequence. This is a sample of how it works: Input: {1, 2, 3} Output: {1}, {1, 2}, {1,2,3} So far, I've been able to solve the ...
SuperJMN's user avatar
  • 233
1 vote
2 answers
148 views

Factory method doesn't meet the DRY principle

I'm using Proto.Actor and I have an actor which acts as a proxy and forwards the messages to the appropriate exchange just because each exchange has different subscription methods, different ...
nop's user avatar
  • 709
2 votes
1 answer
118 views

Parsing information from Excel files

I have to parse information from several Excel files (.xls, .xlsx). The structure of the files is nearly identical except for the columns order. In this case it is ...
nop's user avatar
  • 709
4 votes
1 answer
692 views

Transliterate between Cyrillic and Latin scripts

I want to get a code review on the following transliteration code. I wrote it because there were some libraries that I have tried and they were specifically failing with the name "Yuliya" ...
nop's user avatar
  • 709
1 vote
1 answer
106 views

Finding exceptions and optimisations in weather forecast service

When creating a new Blazor project, there is a page called FetchData which gives an example of a razor page using a service to pull data to a page. I set myself a ...
AT123's user avatar
  • 13
0 votes
2 answers
188 views

Drawing a rectangular playing field

I created a method to print a playing field in the console, but I think there are much better ways to do this than mine. ...
user avatar
1 vote
1 answer
113 views

Asynchronous tasks to subscribe to orders and fills

Pretty straightforward question. The methods SubscribeToOrdersAsync and SubscribeToFillsAsync are pretty similar due to ...
nop's user avatar
  • 709
2 votes
1 answer
451 views

Redis Output Cache Store refactoring - IOutputCacheStore Redis Implementation

This code incorporates the new .NET 7 Output Caching. I would like to get some refactoring tips on the RedisOutputCacheStore class. How to use ...
nop's user avatar
  • 709
0 votes
0 answers
120 views

BaseController with Generic Entity and Model

I created a controller with generic TEntity and TModel so that i will not have to repeat common actions like save/delete for each entity. I just want to ask if this is a good or a bad practice? ...
John Louie Dela Cruz's user avatar
1 vote
1 answer
148 views

File Abstraction Library

This library is a layer of abstraction over file operations in C#. It aims to provide easy file IO syntax, and implicit error handling behaviors, to ensure robustness in scenarios including, but not ...
Divan's user avatar
  • 13
0 votes
0 answers
398 views

Filter duplicate events raised by FileSystemWatcher

As you know about FileSystemWatcher Events, which may fired twice or more according to OS handling, For example creating a .txt file may fires two events (1)For ...
msh's user avatar
  • 1
2 votes
2 answers
414 views

C# Binary Search Tree implementation

I have implemented a Binary Search Tree and would really appreciate it if someone could take time to check it and give me feedback. I try to keep my code clear and simple. Is it readable? Is the API ...
Kirill Dolghi's user avatar
0 votes
1 answer
148 views

ASP.NET Core simple DB cleaner background service

In an application there is a table for one-time-passwords (OTP) which will be sent to users via SMS. These OTPs are needed for a maximum of two hours in order to detect abusing behaviours. A simple DB ...
Parsa99's user avatar
  • 123
2 votes
1 answer
392 views

ASP.NET Core background logger queue with dynamic workers

In a docker compose environment there are several apps that communicate with each other. One of these apps is a logger (a centralized logger). Every part of the system that needs to log something, ...
Parsa99's user avatar
  • 123
0 votes
1 answer
146 views

Improving multiple FirstOrDefault statements on same collection

I'm having multiple FirstOrDefault() statements, in this case 2, on a collection. ...
juFo's user avatar
  • 103
0 votes
0 answers
199 views

ASP.NET Core 6 background DB logger

In an application, many actions need to be logged in the database. but this logging process should not slow down the request. So they should be done in an asynchronous queue or something. This is my ...
Parsa99's user avatar
1 vote
2 answers
141 views

Is this a good way to check for an anagram if sorting is not allowed?

So I decided to lookup some algorithms, and one of the ones I found was.. "Check if the string is an anagram" and without using Google for more than checking what an anagram is, I decided to ...
RileyDan's user avatar
  • 131
1 vote
1 answer
169 views

Serial port class wrapper for serial port object VB.NET

I've been reviewing some code that I maintain recently, and I came across this wrapper object for the serial port class. I'm trying to understand the advantage of this seemingly redundant object: <...
Pslice's user avatar
  • 162
1 vote
1 answer
147 views

NTP client displaying reference, originate, receive and transmit timestamps periodically with graceful shutdown in C#

based on this stackoverflow topic: https://stackoverflow.com/a/12150289/15270760 I have decided to create a simple NTP client displaying difference between NTP server response and DateTime.Now called ...
Artur's user avatar
  • 169
0 votes
1 answer
140 views

Sorting Dictionary in a lexicographical order and applying MD5 encryption

I'm sorting a Dictionary in a lexicographical order and applying MD5 encryption. I would like to wrap the sorting somewhere inside the encryption method or so. Official Java example - here Docs <...
nop's user avatar
  • 709
0 votes
0 answers
126 views

Subscription manager - use cases with same parameters

The idea behind the SubscriptionManager class was not just to keep the subscriptions and resubscribe on reconnect, but also to support multiple callbacks in case of ...
nop's user avatar
  • 709
1 vote
0 answers
331 views

Hangfire context constructor injection

I tried following IHttpContextAccessor pattern but for Hangfire context. What I'm mostly interested in is CustomScope class with Resolve method. I'm using ActivatorUtilities there because otherwise I ...
Medo's user avatar
  • 111
2 votes
2 answers
155 views

Wielding .NET masterfully to encode non-alphanumeric characters into utf-8 hex representation

I have these two methods that work, but I also hate because they almost certainly can be improved. I'm hoping to gain some guidance from others who are more knowledgable of .NET's offering for ...
Greg H's user avatar
  • 23
1 vote
1 answer
67 views

Initializing Class from constructor [closed]

...
Mounir's user avatar
  • 75
1 vote
0 answers
1k views

Implementation of Concurrent List in .NET

I would appreciate review of this implementation of the concurrent list that is, to my knowledge, currently missing in .NET Core. Requirements Thread safe Lock free Ordered Supports get and set by ...
Anonymous's user avatar
  • 111

1
2 3 4 5
25