.net-6.0
Visual Studio 2019 Not Showing .NET 6 Framework
.NET 6 is not supported in VS2019. You might make it work by manually editing your project file, but for a fully supported experience you should upgrade to VS2022.
How to access DbContext in .NET 6 minimal API Program.cs
Scoped services require scope to be resolved. You can create scope via ServiceProviderServiceExtensions.CreateScope: using(var scope = app.Services.CreateScope()) { var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>(); // use context }
Can I add a reference to a .NET Framework DLL from a .NET 6 project?
The Problem Assemblies that “target” (are compiled against/for) .NET Framework (1.0-4.8) may use APIs (types, methods) that are not present in .NET Standard or .NET Core. So if you have a project that targets .NET Standard or .NET Core, and you want to add a reference to an assembly that targets .NET Framework, it may … Read more
Assets file project.assets.json doesn’t have a target for ‘net6.0’ – VS2022
I found the problem and it indeed had to do with restoring NuGet Packages, in that I have a connection to a corporate NuGet repository, and the call to it was breaking due to wrong credentials. What was troubling was that the error did not identify the nature of problem with the connection or the … Read more
Equivalent to UserSettings / ApplicationSettings in WPF for newer .NET versions
You can add the same old good settings file e.g. via the right click on the Properties -> Add -> New Item and search for the “Settings”. The file can be edited in the settings designer and used as in the .net framework projects before (ConfigurationManager, Settings.Default.Upgrade(), Settings.Default.Save, etc. works). Add also the app.config file … Read more
Integration test and hosting ASP.NET Core 6.0 without Startup class
Note that you can switch to generic hosting model (the one using the startup class) if you want. To set up integration tests with the new minimal hosting model you can make web project internals visible to the test one for example by adding next property to csproj: <ItemGroup> <InternalsVisibleTo Include =”YourTestProjectName”/> </ItemGroup> And then … Read more
Where are the using statements/directives in .NET 6
C# 10.0 introduces a new feature called global using directive (global using <fully-qualified-namespace>;) which allows to specify namespaces to be implicitly imported in all files in the compilation. .NET 6 RC1 has this feature enabled by default in new project templates (see <ImplicitUsings>enable</ImplicitUsings> property in your .csproj). For Microsoft.NET.Sdk.Web next namespaces should be implicitly imported … Read more
Problem Updating to .Net 6 – Encrypting String
The reason is this breaking change: DeflateStream, GZipStream, and CryptoStream diverged from typical Stream.Read and Stream.ReadAsync behavior in two ways: They didn’t complete the read operation until either the buffer passed to the read operation was completely filled or the end of the stream was reached. And the new behaviour is: Starting in .NET 6, … Read more
ASP.NET Core 6 how to access Configuration during startup
WebApplicationBuilder returned by WebApplication.CreateBuilder(args) exposes Configuration and Environment properties: var builder = WebApplication.CreateBuilder(args); // Add services to the container. … ConfigurationManager configuration = builder.Configuration; // allows both to access and to set up the config IWebHostEnvironment environment = builder.Environment; WebApplication returned by WebApplicationBuilder.Build() also exposes Configuration and Environment: var app = builder.Build(); IConfiguration configuration = … Read more