Differences between ASP.NET Web Application (.NET Framework) vs ASP.NET Core Web Application (.NET Framework)

Option 1 – ASP.NET Web Application Option 3 – ASP.NET Core Web Application Although both project templates use Full .Net Framework, Option 1 is for creating projects using legacy version of ASP.NET MVC in which we can use Global.asax. Option 3 is totally new concept in which wwwroot folder, using task runners and everything is … Read more

Logging within Program.cs

Accidentally stumbled upon the answer after googling a bit more. using System; using Microsoft.Extensions.Logging; namespace ConsoleApplication { public class Program { public static void Main(string[] args) { var logFactory = new LoggerFactory() .AddConsole(LogLevel.Debug) .AddDebug(); var logger = logFactory.CreateLogger<Type>(); logger.LogInformation(“this is debug log”); } } } Kudos to https://askguanyu.wordpress.com/2016/09/26/net-core-101-e06-net-core-logging/

What does the [Intrinsic] attribute in C# do?

Here’s what I’ve managed to find after a very limited search through dotnet/corefx repository on github. [Intrinsic] marks methods, properties and fields that can be potentially replaced/optimized by JIT. Source code comments say something similar (IntrinsicAttribute.cs): Calls to methods or references to fields marked with this attribute may be replaced at some call sites with … Read more

How to auto log every request in .NET Core WebAPI?

ActionFilter will work until you need to log only requests processed by MVC middleware (as controller actions). If you need logging for all incoming requests, then you need to use a middleware approach. Good visual explanation: Note that middleware order is important, and if your logging should be done at the start of pipeline execution, … Read more

How to use the dotnet-pack –version-suffix with csproj?

According the documentation, the Version property override the version on packing, instead, use the VersionPrefix. <PropertyGroup> <VersionPrefix>1.0.0</VersionPrefix> </PropertyGroup> And use the command to pack solution: dotnet pack –version-suffix beta Optionally you can set VersionPrefix and VersionSuffix in .csproj file. <PropertyGroup> <VersionPrefix>1.0.0</VersionPrefix> <VersionSuffix>alpha</VersionSuffix> </PropertyGroup>

Base Class type for ILogger using Dependency Injection

use a none generic ILogger in your base class, but ILogger<DerivedClass> in your derived class. This way you can simply pass the ILogger to your base class if needed: public abstract class BaseClassExample { private readonly ILogger logger; public class BaseClassExample(ILogger logger) { this.logger = logger; } } and public class DerivedClass : BaseClassExample { … Read more

docker container exits immediately even with Console.ReadLine() in a .NET Core console application

If you switch your app to target .NET Core 2.0, you can use the Microsoft.Extensions.Hosting package to host a .NET Core console application by using the HostBuilder API to start/stop your application. Its ConsoleLifetime class would process the general application start/stop method. In order to run your app, you should implement your own IHostedService interface … Read more

How to reference ASP.NET Core 6 types in .NET 6 library?

You need to add a FrameworkReference to your project file instead of a PackageReference as described here. <ItemGroup> <FrameworkReference Include=”Microsoft.AspNetCore.App” /> </ItemGroup> Right-click your project in the Solution Explorer and select “Edit Project File” to open the file and look for the <ItemGroup> section, creating a new one if it does not exist.

How to force Visual Studio to re-create the SSL certificate for a .NET Core Web Application running Kestrel?

I finally figured it out. For anyone else who runs into this, the steps to fix it are: All localhost certificates must be deleted in certificate manager. They can be found in Personal and Trusted Root The secrets.json file must be deleted. This can be found in \Users\[user]\AppData\Roaming\Microsoft\UserSecrets\ In powershell, re-run dotnet dev-certs https –trust … Read more

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