Skip to main content

280 posts tagged with "C#"

C# Programming Language

View All Tags

Fixed: error CA1852: Type 'WeatherForecast' can be sealed because it has no subtypes in its containing assembly and is not externally visible

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

The first build of a brand-new .NET 10 Web API failed with error CA1852 on the template's own WeatherForecast record. The solution turns on Microsoft's recommended code-quality rules and treats warnings as errors, and one of those rules asks for types like this one to be sealed. Adding that one word fixes it.

Fixed: error NU1008: The following PackageReference items cannot define a value for Version

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

I created an ASP.NET Core Web API project inside a .NET 10 solution that manages package versions centrally, and the template's own restore failed with error NU1008. The template writes a package version into the project file, which central package management doesn't allow. Moving that one version to Directory.Packages.props fixes it.

How to Run Code Only in Development in ASP.NET Core

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

Some code belongs only on a developer's machine: an in-memory store, a relaxed setting, a debugging aid. ASP.NET Core knows which environment it runs in, and one if around builder.Environment.IsDevelopment() keeps that code out of everywhere else. This guide shows the check, where to put it, and how to try the other branch on your own machine.

Join Two Entities in .NET Core Using Lambda and Entity Framework Core

· 11 min read
Jagdish Kumawat
Founder @ Dewiride

Entity Framework Core maps each database table to an entity class and gives you a DbContext to query them. Most of the time you read from a single DbSet, but sooner or later you need data that lives across two tables — exactly what a SQL JOIN gives you. In EF Core, the lambda-based Join() method does the same job, and it translates into real SQL that runs on the database server.

Everything below targets .NET 10 and EF Core 10, the current Long Term Support releases.

How to Read from appsettings.json in ASP.NET Core (C#)

· 9 min read
Jagdish Kumawat
Founder @ Dewiride

appsettings.json is where an ASP.NET Core app keeps its settings — connection strings, API base URLs, feature flags, timeouts. Reading those values comes down to one service, IConfiguration, which ASP.NET Core registers for you. In a console app you build the same thing yourself in a few lines.

This guide covers both, on .NET 10.

Fix: ILogger Type Mismatch in AdapterWithErrorHandler CloudAdapter

· 2 min read
Jagdish Kumawat
Founder @ Dewiride

When creating an AdapterWithErrorHandler class that inherits from CloudAdapter, you might encounter this compile error:

Argument 3: cannot convert from 'Microsoft.Extensions.Logging.ILogger<Microsoft.Agents.Hosting.AspNetCore.IAgentHttpAdapter>' to 'Microsoft.Extensions.Logging.ILogger<Microsoft.Agents.Hosting.AspNetCore.CloudAdapter>'

This happens because you're passing ILogger<IAgentHttpAdapter> to the CloudAdapter base constructor, but it expects ILogger<CloudAdapter>.