Questions tagged [.net-6.0]
For questions about Microsoft's .NET application development framework that are specific to version 6.0+ of the framework. Use only If your question are version-specific
.net-6.0
423
questions
266
votes
14
answers
272k
views
ASP.NET Core 6+ how to access Configuration during startup
In earlier versions, we had Startup.cs class and we get configuration object as follows in the Startup file.
public class Startup
{
private readonly IHostEnvironment environment;
private ...
49
votes
6
answers
13k
views
Problem Updating to .Net 6 - Encrypting String
I'm using a string Encryption/Decryption class similar to the one provided here as a solution.
This worked well for me in .Net 5.
Now I wanted to update my project to .Net 6.
When using .Net 6, the ...
14
votes
3
answers
12k
views
Where are the using statements/directives in .NET 6 and above
I got up and running with Visual Studio 2022 Preview for a couple of days now.
Got the first shock, there is no Startup.cs. Thats ok, a bit of reading, I know Startup is removed.
Today got another ...
22
votes
1
answer
18k
views
Integration test and hosting ASP.NET Core 6.0 without Startup class
To setup unit tests in previous versions of .NET Core, I could host my web App or web API in a test project the following way:
IHost host = Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(...
11
votes
1
answer
1k
views
Nullability and generics in .NET 6
Let's say we have some generic method with 2 parameters:
private void TestConstraints<TKey>(TKey key, TKey? nullableKey)
where TKey : notnull { }
That's perfectly fine from .NET6 ...
5
votes
1
answer
3k
views
Logs not getting written to ApplicationInsights
Here is my .net 6 program.cs basic code. In the Following sample code I am trying to write basic logs into Application insights.
I have Nuget package reference in my project file
<PackageReference ...
280
votes
16
answers
253k
views
Non-nullable property must contain a non-null value when exiting constructor. Consider declaring the property as nullable
I have a simple class like this.
public class Greeting
{
public string From { get; set; }
public string To { get; set; }
public string Message { get; set; }
}
Strangely I get the ...
53
votes
5
answers
75k
views
Can I add a reference to a .NET Framework DLL from a .NET 6 project?
Microsoft recently announced .Net 6.0 as major version. I didn't find any reference where we can use older .NET framework (> 4.7.*) references in .net 6.0 project?
Say, a .NET 6 project will have ...
18
votes
1
answer
24k
views
How to configure NewtonsoftJson with Minimal API in .NET 6.0
I have net6.0 project with minimal api and I would like to use NetwtonsoftJson instead of built in System.Text.Json library for serialization and deserialization.
At the moment I have this ...
3
votes
1
answer
2k
views
How to download files using HttpClient with a ProgressBar?
I created a new class named SiteDownload and added some links to download images:
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
public class ...
216
votes
17
answers
143k
views
Publish error: Found multiple publish output files with the same relative path
When I publish my ABP project I get the following error:
C:\Program Files\dotnet\sdk\6.0.100-rc.1.21458.32\Sdks\Microsoft.NET.Sdk
\targets\Microsoft.NET.ConflictResolution.targets(112,5):
error ...
38
votes
2
answers
6k
views
FileVersionInfo.ProductVersion suddenly contains git commit hash
I have a .NET 6 WPF project and cannot figure out what changed as the ProductVersion of my assembly suddenly contains a git commit hash.
My project file always looked like this, where I also updated ...
16
votes
1
answer
16k
views
How to access DbContext in .NET 6 minimal API Program.cs
I am trying to call EF Core methods on application startup in my Program.cs file, using the .NET 6 minimal API template and get the following error:
System.InvalidOperationException: 'Cannot resolve ...
2
votes
1
answer
1k
views
I need to update state of blazor component when other component changed
I have a blazor page with different components.
Component structure is the following:
page
component1
component11
component2
When event happens on component11, component2 should update ...
106
votes
31
answers
114k
views
Assets file project.assets.json doesn't have a target for 'net6.0' - VS2022
Just a few days ago got this error, after updating to Visual Studio Community 2022 v17.2 (from v17.1.6):
Error NETSDK1005
Assets file 'C:.........XXXXXX.Web\obj\project.assets.json' doesn't have a ...