How to use WebApplicationFactory in .net6 (without speakable entry point)

Note that if you are trying to use xUnit and its IClassFixture<T> pattern, you will run into problems if you just use the InternalsVisibleTo approach. Specifically, you’ll get something like this: “Inconsistent accessibility: base class WebApplicationFactory<Program> is less accessible than class CustomWebApplicationFactory.” Of course you can solve this by making CustomWebApplicationFactory internal but it only … Read more

Remove “Server” header from ASP.NET Core 2.1 application

This solution works on IIS 10+ version and allows to remove x-powered-by and server headers in server response. In IIS 10 a new attribute was added: removeServerHeader. We need to create web.config file in asp.net core application with following content: <?xml version=”1.0″ encoding=”utf-8″?> <configuration> <system.webServer> <security> <requestFiltering removeServerHeader=”true” /> </security> <httpProtocol> <customHeaders> <remove name=”X-Powered-By” /> … Read more

Cannot add duplicate collection entry of type ‘add’ with unique key attribute ‘name’ set to ‘aspNetCore

The answer above didn’t work for me, however DavidG’s comment did solve my problem, so going to post as an answer in case it helps someone else. For me, I was not running it as a sub-application, and a project that had been working for me no issue for over a year suddenly stopped working … Read more

How to configure ASP.net Core server routing for multiple SPAs hosted with SpaServices

Thanks to SteveSandersonMS and chris5287 over on Github for pointing me towards the solution on this. IApplicationBuilder.Map can segregate paths into different areas of concern. If you wrap a call to app.UseSpa in a call to app.Map, the SPA will be handled only for the path specified by the Map call. The app.UseSpa call ends … Read more

Generate .NET Client from Swagger [closed]

You can use the swagger-codegen tool from the swagger project. It produces C# files that use RestClient for the HTTP calls Newtonsoft.Json for json marshalling .NET DataContract for the models. You can either download the cli app or use the online editor. The petstore example models look like this: using System; using System.Text; using System.Collections; … Read more

Unauthorized nuget package from Visual Studio Team Services using asp.net core rc2

I know that it’s not exactly the same issue, but people may come across this one alongside as I did. I have installed VS Community 2019​ and yesterday I decided to remove the VS 2017, but after that, when I tried to restore the Nuget Packages made by the company, it started displaying an error … Read more