How to enable C# 9.0-preview

As of October 2020: Please see @Pac0’s answer here: https://stackoverflow.com/a/64386529/159145 As of June 2020: According to this page in the documentation you need to edit your *.csproj to set the <LangVersion> to preview. Also mentioned in the blog-post about the preview-release, but not the above documentation page, is that you need to update your project’s … Read more

CA1416. How to tell builder that only platform is Windows?

You can mark each windows-specific method with System.Runtime.Versioning.SupportedOSPlatformAttribute e.g. [SupportedOSPlatform(“windows”)] public static void Foo() => Thread.CurrentThread.SetApartmentState(ApartmentState.STA); Mark entire assembly with in AssemblyInfo (if you have one) [assembly: System.Runtime.Versioning.SupportedOSPlatformAttribute(“windows”)] Or edit .csproj file to target windows-specific version of dotnet to make these changes automatic <TargetFramework>net5.0-windows</TargetFramework>

Visual studio 2019 “Unable to connect to web server ‘IIS Express’”

I tried this one and it worked for me: Go to ‘Debug Properties‘ Find ‘Web Server Settings‘ Change the port in ‘App URL‘ section and save the changes Run the application and the same error will appear again Switch the port back to the original port and save the changes Run the application and enjoy … Read more

Docker image for .net 5

As I read here, it is changed to: FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build It is also mentioned on the docker hub with more info: As part of the .NET 5.0 release, all .NET Docker images (including .NET Core 2.1 and 3.1) have transitioned to a new set of Docker repositories described below. … Read more

What changed in .net 5 that makes it not throw when changing dictionary values in foreach

There was a change to the source code of Dictionary<TKey, TValue> to allow updates of existing keys during enumeration. It was commited on April 9, 2020 by Stephen Toub. That commit can be found here along with corresponding PR #34667. The PR is titled “Allow Dictionary overwrites during enumeration” and notes that it fixes issue … Read more

.Net 5 Publish Single File – Produces exe and dlls

Its known issue that described here: https://github.com/dotnet/runtime/issues/36590 And new dev experience provided here: https://github.com/dotnet/designs/blob/main/accepted/2020/single-file/design.md#user-experience So in your case you need use p:IncludeNativeLibrariesForSelfExtract=true additionaly. Full command: dotnet publish -c Release -o publish -p:PublishReadyToRun=true -p:PublishSingleFile=true -p:PublishTrimmed=true –self-contained true -p:IncludeNativeLibrariesForSelfExtract=true or include this flag in .csproj file <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net5.0</TargetFramework> <PublishSingleFile>true</PublishSingleFile> <RuntimeIdentifier>win-x64</RuntimeIdentifier> <PlatformTarget>x64</PlatformTarget> <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract> </PropertyGroup>

tech