C#

C

C#

We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.

Join

Hangfire implementation in Repository pattern

Hi, sorry for newbie question. I am trying to add hangfire to my project. I believe I am using DDD to the best of my ability trying to incorporate hangfire and follow DDD architecture i've hit a snag. here is some code snippet from my hangfire implementation in each layer:...

✅ Need help with regular expression pattern

I am trying to match everything between two given tags using regular expression. For example: ``` string s = "We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase> else."; string startTag = "<upcase>"; string endTag = "</upcase>";...

Extracting values from external data files for a property in `.csproj`?

we are working on mod setup for a unity game installed through steam so we need to import game DLLs from steam library. we wrote a C# snippet that seems to perform that task correctly: ``` var SteamInstallPathFromRegistry = OS == "Windows_NT" ? $"{MSBuild.GetRegistryValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Valve\Steam", "InstallPath")}" : ""; var SteamDir = OS == "Windows_NT" ? SteamInstallPathFromRegistry != "" ? $"{SteamInstallPathFromRegistry}/steamapps": "C:/Program Files (x86)/Steam/steamapps" : $"{Environment.GetEnvironmentVariable("HOME")}/.steam/steam/steamapps";...

✅ what to do when I want ref my ID but the class does not have access to the database

so I am learnign MVC and I my code set up is like this repositiroy - talks to database service class - talks to repos but maps everything to a view model controller talks to my service class...

✅ Class instance reference

I'm having some issues figuring out why my code is behaving like it's taking a "snapshot" of an instance instead of directly referencing it. So I created a custom attribute so that I could check a class for methods with it and add the methods to the list. I had to "register" my methods after creating the instance so that they could access the instance members, and so in the class constructor I added: ```cs...

magic code???

i am running my project in visual studio code exactly the same way with nothing changed, the project has an UI but the important part that sometimes works sometimes not is the fact that sometimes it outputs in the csv files then i delete them and readd them and then it wont work again, i have tried dotnet clean dotnet build restarting machine but i can't find a pattern why sometiems it works sometimes it doesent

✅ code cant find reference to my ID but I am implementing it correctly

Severity Code Description Project File Line Suppression State Details Error CS0103 The name 'customers' does not exist in the current context PharmacyApp D:\Zeeshan\Documents\Pharmacy\PharmacyApp\Services\FeedbackFormService.cs 27 Active
...

Discrepancy between the console result and the expected result.

Good evening, I’m really sorry for the inconvenience, especially since I’m sure it’s a rookie mistake. I have a code, which is executed from a given .txt file which are the following: 5 4.1...

Evaluating Serverless and Backendless Alternatives for MAUI Application Maintenance

I am currently nearing the initial release of a cross-platform MAUI application paired with an ASP.NET API backend. The application allows users to register through the API, which stores user credentials in a SQL database. Upon login, a token is generated and securely stored locally on the device. The core functionality of the app involves offline-first data creation. Data generated offline is synced to the backend via an API endpoint when an internet connection is available. This data is stored in a MongoDB database, associated with the authenticated user ID. If the application is uninstalled and reinstalled, the user can log in again and retrieve their previously saved data. At present, the server-side architecture includes multiple environments (DEV, STA, PROD), with separate instances for the API, SQL databases for user data, key vaults for secrets management, and MongoDB instances for user-generated content....

✅ CODE REVIEW ASP.NET CORE MVC PROJECT

Hello everyone, I am trying to develop an ASP.NET Core MVC project using C#, Entity Framework Core, MS SQL Server but I've got to some point and now I am stuck. This is a senior project that I needed to do for my course but I didn't manage to do it on time and now I am trying to figure out on my own how to get it done...This is my first big project so I am still learning... The project is compiling, there are no errors, everything works but I've got out of ideas how to proceed to satisfy the requirements for the project. I am trying to develop some kind of guest reservation system for a hotel. My database entities are : Booking,Guest, Hotel, HotelRoom, Payment, Room, RoomType, Staff. There is a requirement that we need to have at least 6 entity models, 6 controllers and 15 web pages(views). I think I have satisified the requirement for the models and the web pages, the only thing left is the controller logic. I have 3 controllers so far - HotelController, GuestController, BookingController. I am attaching the requirements and my github repo for the project... Thanks in advance to anyone that shows interest. 🙏 Github Repo: https://github.com/Dimitar47/SoftUni-CSharp-Courses/tree/main/ASP.NET%20Core%20Advanced/17.%20Project%20Defense/HotelApp...

unity render texture and post processing

hi guys i hope everyone having a nice day i am getting in some issue in unity that is completely new to me i have a render texture that is assigned in main camera lets say the player camera and i have a RawImage that aslo assigned to the render texture and i have another camera camera2 so i get rid of the annoying message anyways i wanted to add some effects and sahders but the post processing doesnt work if i am using render texture is there another way?

Implementing IEnumerable<> for a custom hash table data structure to be able to use LINQ

Hello guys, I needed to create a hash table from scratch. Now, I want to use that hash table with LINQ. I read that we need to implement the IEnumerable<>. That done, my IDE yell at me to use the follwing methods: ```C# public IEnumerator<V> GetEnumerator() {...

Too Much Indentation When Rendering a Scriban Template

YI have this little Scriban template for generating a simple C# class: ``` using Cassandra.Mapping.Attributes; namespace {{model.name_space}};...

BackgroundService Question

Hello :D I'd like to get some feedback on the Microsoft.Extensions.Hosting's BackgroundService . The issue i'm facing seems to be a race issue between the Discord client initializing and another hosted service being started and inheriting said client before it is properly initialized. The confusing part is that a second hosted service (the main class handling pretty much the registering of commands, modules, and logging) also inherits the DiscordSocketClient but this service is actually receiving the full initialized instance despite being registered right under InteractionManager. I would love some help on this :( Code: https://paste.mod.gg/acslcflspkxc/0...

hangfire in DDD

hi good folks, I have only given a try to hangfire yesterday. built a simple api project and jammed everything in one layer(added my background tasks in program.cs) just to see what can be done with it and to test the waters. now I wanna incorporate it my existing project which follows DDD architecture(mono). but I'm confused as to where to put what and what layer do I install what?...

MySQL Not Connecting to My Serenity WebAPP

I am having a problem with connecting my c# project to my local mysql running instance. Out of everything I have tried, i am always getting this error ClientConnectionId:00000000-0000-0000-0000-000000000000. Help from anyone will be well appreciated
No description

Table Per Type Inheritance Update Error

I am getting and error: "message": "Error updating student: The instance of entity type 'AppUser' cannot be tracked because another instance with the key value '{Id: 59ade4e2-b505-4579-a797-bf6c57e6b8ef}' is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached." please help me solve this problem. Methods and the entity are within the updateaMethod.txt...

can you call a function in a partial_view?

so I am makign this pharmaceutical mvc app and I for some reason when I do a view Page source it says It cant find my script. so am i allowed to run a script in a partial view I would assume so since its only a naming convention...

How to hide Back Button in Maui 8 Appshell

ok again a tiny little thing that should be a single line of code is driving me nuts, how do i disable the damn back button that appears at the top left of the window? i have tried Shell.NavBarIsVisible="False" in App.xaml, appshell.xaml and i have tried doing it with code in appshell.xaml.cs ```c# protected override void OnNavigating(ShellNavigatingEventArgs args)...