C#

C

C#

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

Join

Why is the antiforgery token in MS example appending the token only on "/" or "/index/html"

I'm working on an angular SPA front end and C# web api backend. I want to use antiforgery cookies. The front end and backend live on the same server on different ports (not sure if any of this is relevant to the question). I've got the antiforgery cookie correctly working - if I visit my page directly, www.mywebsite.com, then the token is appended and everything works fine.. However, if I visit my angular SPA starting at a URL that is not "/" or "/index.html" then the cookie is not appended and I get exceptions in my backend when trying to make calls. I think this is because I am implementing it as suggested here: https://learn.microsoft.com/en-us/aspnet/core/security/anti-request-forgery?view=aspnetcore-8.0#generate-antiforgery-tokens-with-iantiforgery ...

Utf8Json or Jil for Net3.5

Hey there! I'm trying to improve the performance of a game made in an older version of Unity that uses Net 3.5, and want to find a better JSON serializer and deserializer (current is JsonFx). I read about Utf8Json and Jil, but there don't seem to be any 3.5 versions available, even though I have read several articles and StackOverflow posts that mention them. Any help is much appreciated!

Questions/concerns about memory usage in my project

Apologies for the messy formatting, I created this post because of multiple concerns and/or observations while profiling it. The first part is that I'm not very familiar with how GC works or is expected to work. Clearly in the first screenshot the drops are caused by garbage collection, but I'm unsure what's causing the gradual rises in memory. Is this just normal behavior since it seems to always drop to around the same level each time GC runs? Second question: What could cause total memory usage to vary wildly over the duration of a project running? In my case, this is a Discord bot profiled by dotMemory over the course of >24 hours (second screenshot). It reached a peak of 4.91GB used, and now we're currently using 2GB and the lowest total memory used was about 1.3GB. Snapshots have not shown me anything extremely out of the ordinary, it's expected data to be in memory. The only confusing part is that there are large quantities of CancellationTokenSources (third screenshot), despite every instance of one wrapped within a using statement to ensure it was disposed of. I'm very new to disgnosing memory leaks and/or usage issues so if I'm expressing incorrect assumptions or missing anything extremely obvious, let me know. I can post screenshots of my snapshots or anything else that might be relevant if needed....
No description

User built queries on objects

I'm looking at an old app that allows users to build queries to retrieve objects in a list that match that query. It is only querying off a single property on the objects: a Dictionary<string, string> . Each object's dictionary property will always have the same keys. In the current code, it is a massive mess of nested if/else statements. The flow goes like this: 1. User selects key from the dictionary's keys...

Force Clickonce to use a specific port?

How can I force a clickonce setup and the update mechanism to use a specific port? including the initial connection

ILogger<T> extension method "pass the args".

I am trying to create an extension method on ILogger<T> called LogPermissionDenied. I have a custom IPermissionDeniedErrorFragment which is an auto-generated interface from Strawberry shake based on a GraphQL fragment, that doesn't really matter that much, it is just to provide some context. The ILogger<T> has a method called LogError with an overload that accepts an string message and a params object?[] args...

Uninstaller won't remove AppData\Local expanded files.

Hey all, new here. I have a .NET 6 WPF app with an installer project (Microsoft Visual Studio Installer Project 2022) I added and "mostly" works fine. The issue is that the uninstall is not removing the temp files. I have an AppData\local collection of expanded on-demand files, but when uninstalled, it leaves them behind. Is there a native way to have the uninstaller remove them, or do I need to make a CustomActions class to explicitly remove them?...

Is List.Contains(Object) checks by address or by value?

Hi, if I have the following List/Dictionary (I know it doenst matter in this question): I want to check if a drink is inside the dictionary like this - Drinks.ContainsKey(drink) I'm not sure if it will check by value like if all the values inside the drink are equal or it will check if this is the identical drink (by adress). I want to point out that I overrided Equals inside of Item....
No description

Delay While Page Loading

while navigation from one page to another is taking so much delay why here i have attached the three Document and one video in Basci text i have the App.cs And Mauiprogram.cs all the This ...

Issue installing NUnit

Hello, I have been trying to install NUnit to add unit tests to my main project. To do so, I created a new project on Rider. The file structure is the following: \ \MainProject.sln \MainProject.csproj \TestProject\TestProject.csproj...

✅ building nativeaot project with static library still requires library to be copied

i have tried to build nativeaot project with: ```xml <ItemGroup> <DirectPInvoke Include="raylib"/> <NativeLibrary Include="raylib.lib"/>...
No description

✅ cleanup

dotnet clean not removing obj and and bin folders

ViewFeatures, but something that isn't deprecated?

Trying to use this kind of code line: public IEnumerable<SelectListItem> AuthorList { get; set; } Works fine, if I have: using Microsoft.AspNetCore.Mvc.Rendering;...

".NET MAUI iOS Simulator Error: 'Please connect the device' with UDID, stuck after build"

I'm running into an issue with .NET MAUI on iOS. I keep getting the error: Please connect the device ':v2:udid=8B56F350-7124-4C30-A582-30BC84EF1BE6'... This UDID is for my simulator, and I'm unsure how to resolve this. I've followed the official MAUI docs, but still no luck. ...
No description

.Net 8 Web Api Config

Deployed webapi in IIS. Previously using .net 4.5.* where changing config in application settings in UI and restarting for dynamic change. Now in .Net 8 using Environment.GetenvironmentVariable, on publishing generated web.config file but adding values doesn't reflect and added values to pool also none but when added to system level it works but it takes time to recognise. Tried ChatGPT and older relevant question here and none working can someone point me in the best direction? TIA

✅ How do I pin both NET 8 and NET 6 sdk versions in global.json?

hi everyone! if I pin the 8.0.204 sdk in global.json for some reason it wants to pull version 6.0.35 of the Microsoft.NETCore.App.Ref nuget package. is there a way to pin both the 8.0.x and 6.0.x versions of those nuget packages? at my company we are using internal nuget repositories and we don't have a way to pull those internal SDK nuget packages automatically

UWP MAUI building problem

Hi ! So, I was testing Jetbrains Rider, as I have a free student account, and when I want to run on debug the basic MAUI template for Windows (UWP), it just doesn't work and throw me this error : Registering UWP app with manifest: D:\Programmation\CsharpProjects\MauiApp3\MauiApp3\bin\Debug\net8.0-windows10.0.19041.0\win10-x64\AppX\AppxManifest.xml arch X64... Register application failed return code is 1. STDERR: ERROR: The asynchronous operation was failed: E_ACCESSDENIED General access denied error (hresult_error:80070005)[location] = Z:\BuildAgent\work\40149736ac453055\dotnet\Rider\Native\Solution\winrt_launcher\src\utility.hpp(41)[function] = void __cdecl jbrs::wait_for_finished(const struct winrt::com_ptr<struct IAsyncInfo> &)[uri] = D:\Programmation\CsharpProjects\MauiApp3\MauiApp3\bin\Debug\net8.0-windows10.0.19041.0\win10-x64\AppX\AppxManifest.xml...

Windows Authentication

Hello, I have this blazor application that uses Windows Authentication. Everything works well but not on some deployments, I know Negotiate should only use HTTP1.1 but in some of these deployments it only uses HTTP2 and doesn't try to downgrade. I have checked everything I know including kestrel which I already use HTTP1andHTTP2...

Migration issues -EF core.

I am creating a DDD application with EFcore but I am not able to use the migration because of the following error. Does anyone know how to solve this? can provide code snippets if needed...
No description