C#

C

C#

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

Join

✅ doubts about migrations

what's bothering me: every time we do a migration on our main service we have 8K+ lines more to commit in the project (which btw means that for example in the vs search i have to exclude migrations path - thing that took ages because it didn't work - or it's useless) it's not a big deal di per se, but i find it kinda silly that project is what, ~150K loc, and we have 1+ M loc of migrations (around 100 tables (i'm working on isolating some parts, but i don't know if/when that'll happen) and almost 400 migrations) because every migration (ef core) does a new snapshot so is this how it's supposed to be? is it not? would i be better off moving migrations to another solution? is there a way to save some code?...

How do I create my own file extension?

Help please. In short: I need to create my own file extension, for example levelData.ldat, and so that only the program can access this file (read and modify it), but not the user in any case

NU1902 NU1903 warnings

So I'm getting these warnings in my DotNet solution. I'm still learning Dotnet and don't know how to address problems. I've tried exploring the internet but can't figure out how to fix these. Could anyone please clarify what these warnings are for and how to resolve them?
No description

Troubleshooting xaml - initialize window

```xml <Window x:Class="Othello.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Othello Game" Height="75" Width="500">...
No description

When 2 objects occupy the same cords , one kills the other , need help.

I have tried some things but they dont work i need some ideas to make this work.

.NET 8.0, PostgreSql and left over Idle sessions

I have a .NET 8 webapp and we've done a dumb and manually handled postgres database connections throughout our classes.. I think this could be the root of my problems really... We new up connections and pass the connection around through our various classes, we end up sometimes passing the same connection down 2,3,4 times, re-using it, with the final disposal being quite some time later... making it hard to follow where idle connections are even coming from. One clue might be that the Idle connections don't even have a query associated with them... (making it really hard to pinpoint where they are coming from). I still feel like a noob C# developer (about 2 yr) and haven't touched things like dependency injection yet.. does anyone here know of any good resources for setting up and managing postgres DB connections that get implemented across many classes? My issues is we have leaky connections, even though i've been careful to go through the entire project and wrap ever instance of NpgsqlConnection/NpgsqlCommand in using statements and (tried to) implement the IDisposable interface for each class using the postgres connections. But i'm still finding some leaky connections/sessions building up over time....

I need help implementing recursion in a general way

Help I realise you need to understand recursion to understand the rest of DSA like graphs etc but I'm not fully confident So I know that recursion uses a base case and a recursive case but how can I come up with these on the spot like nothing because you can turn any for loop or while loop into a recursive function?...

do defined route added to the the routes table when the app.Run() executed or before?

I previously asked about the roles of UseRouting and UseEndpoints, and the answer was that UseRouting matches incoming requests against predefined routes in the route table. My question now is about the route table itself: Are the routes added to the route table before or after app.Run() is executed? I’m asking this because, during a debugging session, the application seems to go through the middleware pipeline step by step, executing each middleware until app.Run() is reached, after which the p...

Json TypeInfoResolver GetCustomAttribute returning wrong result

```csharp public void ModifyTypeInfo(JsonTypeInfo ti) { if (ti.Kind != JsonTypeInfoKind.Object) return; ...
No description

Custom Logger

Hi all, been trying to figure this out for a bit now but I'm not sure what's happening. I am writing a custom extension for Microsoft.Extensions.Logging to write to a Sql Server database with a particular schema. However, I'd opted to make it as generic as possible. After doing a lot of research, I've created a DbLoggingProvider and a MSSqlDatabaseLogger. The logging provider creates new instances of the database logger, as expected, and the database logger expects an instance of a type implementing ILogAgent which it forwards its log method to. The log agent is responsible for performing the database-specific operations. However, when doing unit tests, I am unable to prove that logging works. In fact, it appears to not. Take the following test....

✅ Swashbuckle to other swagger UI

Did anyone move the swagger UI from swashbuckle to other ones like Scala? Need guidelines for the same?

SqlConnection Connection Disposed

Hi all, I have class library which provides a custom type called SqlServerAccessor This custom type wraps a SqlConnection and its ctor accepts a connection string, news up a SqlConnection, and calls _connection.Open(). This type implements IDisposable and is intended to be used as follows:...

✅ cos(90) = 6.... ???

I want c# to calculate the value of sin(90), but it outputs a number, wich is bigger, than 1. How?
No description

Value not being displayed on the page

showadress.aspx <%@ Page Title="" Language="C#" MasterPageFile="~/guestmasterpage.Master" AutoEventWireup="true" CodeBehind="showadress.aspx.cs" Inherits="NoozhaRamputh21443mstore.tutorials.week5.showadress" %> <%@ Register TagPrefix="uc" TagName="address" Src="~/tutorials/week5/addressform.ascx" %> ...

xUnit and Dependency Injection

Hello, I have not ran too many unit testings up through my time, but recently getting into a bit more of a heavy program where unit testing will be crucial. The project is dependent on Dependency Injection, and I was wondering if its possible to run unit tests on methods from DI services...?...

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Data.SqlClient

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Data.SqlClient=5.0.0.0 even when i use 5.2.2 So, i create a little web-api (.net 8) which only will be available to other services on the published server. When it's finished it should access some db-tables and create excel-files out of them - depending on request params. It's really simple, it only requires ClosedXML (not yet added) & Microsoft.Data.SqlClient...

I have a list of students and their grades that I want to sort based on grades

After user inputs name and grades of students, I want to be able to sort and output them with the students with highest grades first. I'm not sure how to go about this using a list and grades ranging from F-A+ student class: https://hatebin.com/csfqzfdnyi program: https://hatebin.com/ahasrqnvmz...

asp attribute span not getting styled like plain span

Why is it that only the plain span is being styled and not the asp span? How can I fix this? ```html <span class="danger" asp-validation-for="SomeModel.Number"></span> <span class="danger">some span</span>...

Failing to recompile Unity.SourceGenerators as type "Enumerator" isn't a valid name or namespace.

Hello! I have been trying to recompile Unity.SourceGenerators so I can reimplement it in a solution, but the class TypeNameHelper.cs has a field where it attempts to initialize a class/type "Enumerator", but VS can't find it. I've tried the potential solutions, such as IEnumerator, enum, and IEnumerable name changes, as well as some formatting changes, but nothing seems to resolve it. My main question is is this just a missing class/dependency I should have in the Unity.SourceGenerators project, or is it something that's just an older class that's now been replaced with something else? Picture attached, let me know if you need any more info, thanks!...
No description