Questions tagged [.net-core]
.NET Core is an open-source successor of the .NET Framework. It can be used in a wide variety of applications and verticals, ranging from servers and data centers to apps and devices. .NET Core is supported by Microsoft on Windows, Linux and macOS.
.net-core
45,030
questions
2893
votes
13
answers
426k
views
What are the correct version numbers for C#?
What are the correct version numbers for C#? What came out when? Why can't I find any answers about C# 3.5?
This question is primarily to aid those who are searching for an answer using an incorrect ...
2093
votes
14
answers
1.5m
views
AddTransient, AddScoped and AddSingleton Services Differences
I want to implement dependency injection (DI) in ASP.NET Core. So after adding this code to ConfigureServices method, both ways work.
What is the difference between the services.AddTransient and ...
1019
votes
15
answers
238k
views
What is the difference between .NET Core and .NET Standard Class Library project types?
In Visual Studio, there are at least three different types of class libraries you can create:
Class Library (.NET Framework)
Class Library (.NET Standard)
Class Library (.NET Core)
While the first ...
724
votes
31
answers
393k
views
How to check if a number is a power of 2
Today I needed a simple algorithm for checking if a number is a power of 2.
The algorithm needs to be:
Simple
Correct for any ulong value.
I came up with this simple algorithm:
private bool ...
558
votes
42
answers
412k
views
Assets file project.assets.json not found. Run a NuGet package restore
I'm trying to use nopCommerce(Which is written in .NET Core) but when I want to run the project I face 52 Errors telling me Run a nuget package restore
Assets file ~\obj\project.assets.json' not ...
522
votes
16
answers
379k
views
Command dotnet ef not found
I'm following the docs in order to create an initial migration. When I execute dotnet, I get the help section, meaning that the PATH works properly.
Then I try to execute the command below from the ...
483
votes
5
answers
301k
views
Build .NET Core console application to output an EXE
For a console application project targeting .NET Core 1.0, I cannot figure out how to get an .exe to output during build. The project runs fine in debug.
I've tried publishing the project, but that ...
458
votes
20
answers
571k
views
How to unapply a migration in ASP.NET Core with EF Core
When I run PM> Remove-Migration -context BloggingContext in VS2015 with an ASP.NET Core project using EF Core, I get the following error:
System.InvalidOperationException: The migration '...
448
votes
29
answers
879k
views
How to read AppSettings values from a .json file in ASP.NET Core
I have set up my AppSettings data in file appsettings/Config .json like this:
{
"AppSettings": {
"token": "1234"
}
}
I have searched online on how to read AppSettings values from .json ...
429
votes
11
answers
216k
views
What's the difference between .NET Core, .NET Framework, and Xamarin?
Microsoft now has .NET Core, .NET Framework and Xamarin (Mono) in its family.
It seems to be a lot of overlap here. What's the difference between these types of .NET Platforms? When should I choose to ...
428
votes
21
answers
529k
views
How to determine if .NET Core is installed
I know that for older versions of .NET, you can determine if a given version is installed by following
https://support.microsoft.com/en-us/kb/318785
Is there an official method of determining if ....
344
votes
11
answers
135k
views
What is ".NET Core"?
Recently in an official .NET Framework Blog it was announced that .NET Core is going open source.
Ironically, the author mentions that what .NET Core is will be explained in the next post. Some more ...
340
votes
8
answers
192k
views
Equivalent to AssemblyInfo in dotnet core/csproj
Since dotnet core moved back to the .csproj format, there is a new autogenerated MyProject.AssemblyInfo.cs which contains, among others:
[assembly: AssemblyCompany("MyProject")]
[assembly: ...
338
votes
8
answers
189k
views
.NET Core vs Mono
What is the difference between .NET Core and Mono?
I found a statement on the official site that said: "Code written for it is also portable across application stacks, such as Mono."
My goal is to ...
305
votes
3
answers
463k
views
How to get HttpContext.Current in ASP.NET Core? [duplicate]
We are currently rewriting/converting our ASP.NET WebForms application using ASP.NET Core. Trying to avoid re-engineering as much as possible.
There is a section where we use HttpContext in a class ...
299
votes
5
answers
184k
views
.NET Core vs ASP.NET Core
What exactly is the difference between .NET Core and ASP.NET Core?
Are they mutually exclusive? I heard ASP.NET Core is built on .NET Core, but it can also be built on the full .NET framework.
So ...
291
votes
10
answers
961k
views
How to remove item from list in C#?
I have a list stored in resultlist as follows:
var resultlist = results.ToList();
It looks something like this:
ID FirstName LastName
-- --------- --------
1 Bill Smith
2 John ...
283
votes
15
answers
483k
views
How to read values from the querystring with ASP.NET Core?
I'm building one RESTful API using ASP.NET Core MVC and I want to use querystring parameters to specify filtering and paging on a resource that returns a collection.
In that case, I need to read the ...
282
votes
7
answers
42k
views
.NET Standard vs .NET Core
I have read about the difference between .NET Standard and .NET Core, but I really don't know what the difference is, or when to choose a .NET Standard library project and when to choose a .NET Core ...
275
votes
11
answers
217k
views
Using 'UseMvc' to configure MVC is not supported while using Endpoint Routing
I had an Asp.Net core 2.2 project.
Recently, I changed the version from .net core 2.2 to .net core 3.0 Preview 8. After this change I see this warning message:
using 'UseMvc' to configure MVC is ...
271
votes
15
answers
228k
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 ...
270
votes
9
answers
227k
views
How to run .NET Core console application from the command line
I have a .NET Core console application and have run dotnet publish. However, I can't figure out how to run the application from the command line. Any hints?
269
votes
4
answers
246k
views
.NET Core DI, ways of passing parameters to constructor
Having the following service constructor
public class Service : IService
{
public Service(IOtherService service1, IAnotherOne service2, string arg)
{
}
}
What are the choices of ...
252
votes
29
answers
211k
views
Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found
I am working on a fabric application where I have configured HTTPS. It is throwing an exception though I have a valid installed certificate.
241
votes
28
answers
104k
views
Unable to find testhost.dll. Please publish your test project and retry
I have a simple dotnet core class library with a single XUnit test method:
TestLib.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0&...
240
votes
18
answers
124k
views
.NET Core MVC Page Not Refreshing After Changes
I'm building a .NET Core MVC on the latest version 2.2. I have a problem when I make changes to the CSHTML file and refresh the page, my changes are not reflected in the browser. I have to restart the ...
238
votes
14
answers
381k
views
Automatically set appsettings.json for dev and release environments in asp.net core?
I've defined some values in my appsettings.json for things like database connection strings, webapi locations and the like which are different for development, staging and live environments.
Is there ...
229
votes
6
answers
347k
views
Return file in ASP.Net Core Web API
Problem
I want to return a file in my ASP.Net Web API Controller, but all my approaches return the HttpResponseMessage as JSON.
Code so far
public async Task<HttpResponseMessage> ...
214
votes
12
answers
93k
views
Should I take ILogger, ILogger<T>, ILoggerFactory or ILoggerProvider for a library?
This may be somewhat related to Pass ILogger or ILoggerFactory to constructors in AspNet Core?, however this is specifically about Library Design, not about how the actual application that uses those ...
213
votes
7
answers
182k
views
Is ConfigurationManager.AppSettings available in .NET Core 2.0?
I've got a method that reads settings from my config file like this:
var value = ConfigurationManager.AppSettings[key];
It compiles fine when targeting .NET Standard 2.0 only.
Now I need multiple ...
205
votes
5
answers
145k
views
How to SetBasePath in ConfigurationBuilder in Core 2.0
How can I set the base path in ConfigurationBuilder in Core 2.0.
I have googled and found this question, this from Microsoft docs, and the 2.0 docs online but they seem to be using a version of ...
194
votes
9
answers
182k
views
Copy files to output directory using csproj dotnetcore
So my issue is pretty simple. I have some files that I want to be copied to the build output directory whether it is a debug build or a release publish. All of the information I can find is about the ...
192
votes
11
answers
191k
views
Unable to resolve ILogger from Microsoft.Extensions.Logging
I've configured my console application's Main like so
var services = new ServiceCollection()
.AddLogging(logging => logging.AddConsole())
.BuildServiceProvider();
And then I try to use it ...
191
votes
3
answers
94k
views
Determine Operating System in .NET Core
How can I determine which operating system my .NET Core app is running on?
In the past I could use Environment.OSVersion.
What is the current way to determine whether my app is running on Mac or ...
185
votes
6
answers
248k
views
Send HTTP POST message in ASP.NET Core using HttpClient PostAsJsonAsync
I want to send dynamic object like
new { x = 1, y = 2 };
as body of HTTP POST message. So I try to write
var client = new HttpClient();
but I can't find method
client.PostAsJsonAsync()
So I ...
184
votes
7
answers
215k
views
The default XML namespace of the project must be the MSBuild XML namespace
I cloned the ASP.NET Core SignalR Repo locally, and try opening the solution from within the following environment.
IDE
Microsoft Visual Studio Enterprise 2015
Version 14.0.25431.01 Update 3
...
183
votes
7
answers
192k
views
How to auto create database on first run?
My application being ported to .NET Core will use EF Core with SQLite. I want to automatically create the database and tables when the app is first run. According to documentation this is done using ...
178
votes
54
answers
444k
views
HTTP Error 500.30 - ANCM In-Process Start Failure
I was experimenting with a new feature that comes with .NET core sdk 2.2 that is supposedly meant to improve performance by around 400%.
Impressive so I tried it out on my ABP (ASP.NET Boilerplate) ...
178
votes
11
answers
202k
views
How to log to a file without using third party logger in .Net Core?
How to log to a file without using third party logger (serilog, elmah etc.) in .NET CORE?
public void ConfigureServices(IServiceCollection services)
{
services.AddLogging();
}
public void ...
175
votes
6
answers
110k
views
How do I get .NET Core projects to copy NuGet references to the build output?
I'm trying to write a plugin system with .NET Core, and one of my requirements are to be able to distribute the plugin DLL along with its dependencies to the user for install.
However, I can't figure ...
175
votes
6
answers
106k
views
Pros and cons of AppSettings vs applicationSettings (.NET app.config / Web.config)
When developing a .NET Windows Forms Application we have the choice between those App.config tags to store our configuration values. Which one is better?
<configuration>
<!-- Choice 1 --&...
174
votes
15
answers
198k
views
Homebrew refusing to link OpenSSL
I'm on: OSX 10.11.6, Homebrew version 0.9.9m OpenSSL 0.9.8zg 14 July 2015
I'm trying to play with with dotnetcore and by following their instructions,
I've upgraded/installed the latest version of ...
173
votes
11
answers
178k
views
ASP.NET Core configuration for .NET Core console application
ASP.NET Core support a new configuration system as seen here:
https://docs.asp.net/en/latest/fundamentals/configuration.html
Is this model also supported in .NET Core console applications?
If not ...
164
votes
12
answers
103k
views
What's the difference between SDK and Runtime in .NET Core?
I've read many articles, including this one, yet I can't still figure out what's the difference, and they have not explained it either in simple terms or at all.
Can someone please clarify what's the ...
161
votes
15
answers
238k
views
How to use appsettings.json in Asp.net core 6 Program.cs file
I'm trying to access appsettings.json in my Asp.net core v6 application Program.cs file, but in this version of .Net the Startup class and Program class are merged together and the using and another ...
159
votes
2
answers
53k
views
What are .NET Platform Extensions on docs.microsoft.com?
There is a framework-level navigation element at Microsoft Docs called ".NET Platform Extensions". It contains docs on recently added APIs like System.IO.Pipelines and System.Threading.Channels for ...
158
votes
10
answers
343k
views
How to update record using Entity Framework Core?
What is the best approach to update database table data in Entity Framework Core?
Retrieve the table row, do the changes and save
Use keyword Update in DB context and handle exception for item not ...
156
votes
2
answers
8k
views
If (false == true) executes block when throwing exception is inside
I have a rather strange problem that is occurring.
This is my code:
private async Task BreakExpectedLogic()
{
bool test = false;
if (test == true)
{
Console.WriteLine("Hello!");
...
148
votes
12
answers
184k
views
Setting the version number for .NET Core projects - CSPROJ - not JSON projects
This question is very similar to Setting the version number for .NET Core projects, but not the same. Using the latest stable version of .NET Core at the time of writing (1.1) and VS2017, .NET Core ...
148
votes
21
answers
104k
views
Auto Versioning in Visual Studio 2017 (.NET Core)
I have spent the better part of a few hours trying to find a way to auto-increment versions in a .NETCoreApp 1.1 (Visual Studio 2017).
I know the the AssemblyInfo.cs is being created dynamically in ...