LINQ ForEach method skips Console.WriteLine() on each iteration, then dumps all the logs when loop is done. Why?

Advertisements I have this piece of code: [Test] public void LinqConsoleOutputTest() { Enumerable.Range(0, 10).ToList().ForEach(_ => { Thread.Sleep(500); Console.WriteLine($"Slept…"); }); } And to my surprise the code was executing around 5 seconds as expected, but it did not print to the console. It just dumped all 10 logs when it finished ForEach loop. And I am… Read More LINQ ForEach method skips Console.WriteLine() on each iteration, then dumps all the logs when loop is done. Why?

Command 'update-database' is not working in .NET 6 Entity Framework for API

Advertisements Command update-database is not working in .NET 6 entity framework for API. Console window displays an error The ConnectionString property has not been initialized after I run the command update-database. Command add-migration is working fine. appsettings.json file: { "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "AllowedHosts": "*", "ConnectionStrings": { "DefaultConnection": "Server=(localdb)\\mssqllocaldb;… Read More Command 'update-database' is not working in .NET 6 Entity Framework for API

ASP.NET Core 6 Web API – serializing public fields

Advertisements I have the requirement that my web controller needs to return a class with only public fields. E.g. I have public class RunningScenario { public int Id; public string Name; } and want to return this from my controller like this [ApiController] [Route("api/[controller]")] public class ScenarioController : ControllerBase { [HttpPost("start")] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status200OK)] public… Read More ASP.NET Core 6 Web API – serializing public fields

How to make dotnet api entrypoint landing directly to swagger docs

Advertisements I have this configuration for dotnet swagger gen: builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Demo", Version = "v1", Description = "This is a demo api" }); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); Is there any way to config so that when user goes to localhost:port/ lands… Read More How to make dotnet api entrypoint landing directly to swagger docs

dotnet 6 unable to find async

Advertisements the title said it all notnet6 is unable to find async, this is the error I get /home/user1/Documents/GitHub/YTD/Core/main.cs(19,16): error CS0246: The type or namespace name ‘async’ could not be found (are you missing a using directive or an assembly reference?) [/home/user1/Documents/GitHub/YTD/Core/Core.csproj] code public async Ytd(string[] args) { Console.WriteLine(0); response = "https://www.youtube.com/playlist?list=PLda3VoSoc_TSBBOBYwcmlamF1UrjVtccZ";//args[0]; extention = args[1];… Read More dotnet 6 unable to find async

Cannot find System.Xaml in .net 6

Advertisements I created a console application with a target framework of .net 6.0 in order to write a custom Xaml writer. This is the project configuration: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net6.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> I want to extend the XamlXmlWriter class but I can’t import it. If I add using System.Xaml I get: The type… Read More Cannot find System.Xaml in .net 6