What is “.NET Core”?

From the .NET blog Announcing .NET 2015 Preview: A New Era for .NET: .NET Core has two major components. It includes a small runtime that is built from the same codebase as the .NET Framework CLR. The .NET Core runtime includes the same GC and JIT (RyuJIT), but doesn’t include features like Application Domains or … Read more

Where is HttpContent.ReadAsAsync?

It looks like it is an extension method (in System.Net.Http.Formatting): HttpContentExtensions Class Update: PM> install-package Microsoft.AspNet.WebApi.Client According to the System.Net.Http.Formatting NuGet package page, the System.Net.Http.Formatting package is now legacy and can instead be found in the Microsoft.AspNet.WebApi.Client package available on NuGet here.

How to check whether a string is a valid HTTP URL?

Try this to validate HTTP URLs (uriName is the URI you want to test): Uri uriResult; bool result = Uri.TryCreate(uriName, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp; Or, if you want to accept both HTTP and HTTPS URLs as valid (per J0e3gan’s comment): Uri uriResult; bool result = Uri.TryCreate(uriName, UriKind.Absolute, out uriResult) && (uriResult.Scheme == … Read more

How to specify the port an ASP.NET Core application is hosted on?

In ASP.NET Core 3.1, there are 4 main ways to specify a custom port: Using command line arguments, by starting your .NET application with –urls=[url]: dotnet run –urls=http://localhost:5001/ Using appsettings.json, by adding a Urls node: { “Urls”: “http://localhost:5001” } Using environment variables, with ASPNETCORE_URLS=http://localhost:5001/. Using UseUrls(), if you prefer doing it programmatically: public static class … Read more

What is the purpose of nameof?

What about cases where you want to reuse the name of a property, for example when throwing exception based on a property name, or handling a PropertyChanged event. There are numerous cases where you would want to have the name of the property. Take this example: switch (e.PropertyName) { case nameof(SomeProperty): { break; } // … Read more

I am getting Failed to load resource: net::ERR_BLOCKED_BY_CLIENT with Google chrome

These errors are usually generated from an ad blocking plugin, such as Adblock Plus. To test this use either a different browser or uninstall the ad blocking plugin (right clicking the extension by the URL bar and clicking “Remove from Chrome…”). There is an easier way to temporarily disable an extension. In Chrome, opening an … Read more

Warning: Found conflicts between different versions of the same dependent assembly

This warning means that two projects reference the same assembly (e.g. System.Windows.Forms) but the two projects require different versions. You have a few options: Recompile all projects to use the same versions (e.g. move all to .Net 3.5). This is the preferred option because all code is running with the versions of dependencies they were … Read more

Running multiple async tasks and waiting for them all to complete

Both answers didn’t mention the awaitable Task.WhenAll: var task1 = DoWorkAsync(); var task2 = DoMoreWorkAsync(); await Task.WhenAll(task1, task2); The main difference between Task.WaitAll and Task.WhenAll is that the former will block (similar to using Wait on a single task) while the latter will not and can be awaited, yielding control back to the caller until … Read more

How to find the Number of CPU Cores via .NET/C#?

There are several different pieces of information relating to processors that you could get: Number of physical processors Number of cores Number of logical processors. These can all be different; in the case of a machine with 2 dual-core hyper-threading-enabled processors, there are 2 physical processors, 4 cores, and 8 logical processors. The number of … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)