LINQ: Add RowNumber Column

Use the method-syntax where Enumerable.Select has an overload with the index: var myResult = someTable.Select((r, i) => new { Row = r, Index = i }) .Where(x => x.Row.someCategory == someCategoryValue) .OrderByDescending(x => x.Row.createdDate); Note that this approach presumes that you want the original index of the row in the table and not in the … Read more

Could not load file or assembly ‘System.Memory, Version=4.0.1.’ in Visual Studio 2015

If this error is appearing in an IIS app such as ASP.NET, then there is a high probability that you are missing a binding redirect in the web.config. When you install from Nuget, you should see a binding redirect in the web.config. If you deploy the application to another machine but fail to set up … Read more

‘Unable to resolve service for type ¨Microsoft.entityFrameworkCore.DbContextOptions¨1[LibraryData.LibraryContext] while attempting to activate

I fixed this error by specifying –project and –startup-project options to Entity Framework Core CLI tools like this: dotnet ef database update –verbose –project CommandService.Data –startup-project CommandService –project means which project contains the DbContext class –startup-project means which project contains the database connection information and other information.

How can I remove the platforms I do not need to compile for in .net MAUI?

Required Change In your .csproj file, remove the targets for the platforms you aren’t building for, reducing it to the following: <TargetFrameworks>net6.0-maccatalyst</TargetFrameworks> <TargetFrameworks Condition=”$([MSBuild]::IsOSPlatform(‘windows’))”>$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks> Optional Changes In your .csproj file, remove the supported version information for the platforms you aren’t building for, reducing it to the following: <SupportedOSPlatformVersion Condition=”$([MSBuild]::GetTargetPlatformIdentifier(‘$(TargetFramework)’)) == ‘maccatalyst'”>14.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition=”$([MSBuild]::GetTargetPlatformIdentifier(‘$(TargetFramework)’)) == ‘windows'”>10.0.17763.0</SupportedOSPlatformVersion> … Read more

C# 10: Disable Default Global Using

<ImplicitUsings>disable</ImplicitUsings> has to be added to the PropertyGroup in the csproj-file. For example: <Project Sdk=”Microsoft.NET.Sdk”> <PropertyGroup> <TargetFramework>net6.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>disable</ImplicitUsings> </PropertyGroup> </Project> If you are using a beta version of .NET 6, you will have to use <DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>.

Host.CreateDefaultBuilder vs Host.CreateApplicationBuilder in .NET Platform Extension 7

It is documented a bit here and here. The general idea was to move away from calbacks and move to linear code for configuring everything Code samples from the link… Web var builder = WebApplication.CreateBuilder(); builder.Logging.AddConsole(); builder.Services.AddOptions<MyOptions>().BindConfiguration(“MyConfig”); builder.Services.AddHostedService<MyWorker>(); var app = builder.Build(); app.MapGet(“/”, () => “Hello World”); app.Run(); Non-Web var builder = Host.CreateApplicationBuilder(); builder.Logging.AddConsole(); builder.Services.AddOptions<MyOptions>().BindConfiguration(“MyConfig”); … Read more

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