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,017
questions
84
votes
8
answers
89k
views
Remotely connect to .net core self hosted web api
I have a simple .net core web api with one action:
[Route("[action]")]
public class APIController : Controller
{
// GET api/values
[HttpGet]
public string Ping()
{
return ...
83
votes
7
answers
159k
views
How to read/write files in .Net Core?
What are the options to read/write files in .Net Core?
I am working on my first .Net Core app and looking for
File.Read*/File.Write* functions (System.IO from .Net) alternatives.
83
votes
8
answers
35k
views
Visual Studio 2017 cannot update Microsoft.NETCore.App package ("Blocked by project")
I have a dotnet core app that is targetting Microsoft.NETCore.App 1.1.2. I created a test project to test against that project but when building I noticed this warning:
I open the NuGet Package ...
82
votes
10
answers
118k
views
How to set start page in dotnet core web api?
I try to build a web application with dotnet core web api,but i do not know how to set index.html as start page which can be done with dotnet framework web api easily. And i tried to use app....
82
votes
10
answers
293k
views
instance of entity type cannot be tracked because another instance with same key value is tracked [closed]
I'm using generic repository pattern in asp.net core 2.0 which can not dispose repository object, when I am going to update the entry its updated for one time successfully but when I am trying to ...
82
votes
5
answers
63k
views
How do I exclude files/folders from a .NET Core/Standard project?
In .NET Core and .NET Standard projects, if you put files and folders within the project directory, they are automatically picked up by Visual Studio; essentially they are part of the project.
What ...
82
votes
14
answers
109k
views
An assembly specified in the application dependencies manifest (...) was not found
I upgraded Microsoft.AspNetCore from 2.0.3 to 2.0.5 and my WebAPI project, although running successfully locally, fails to start in production (IIS). Everything was fine in production until this ...
82
votes
2
answers
29k
views
What is project.lock.json?
I followed the instruction to create new .NET Core project and ran this from cmd:
dotnet new
dotnet restore
The second statement creates project.lock.json that contains a lot of garbage (not really ...
81
votes
4
answers
75k
views
Is ApiController deprecated in .NET Core
Is it true that "ApiController will get deprecated in .NET Core"? Asking since I'm planning to use it in new projects.
81
votes
6
answers
62k
views
How to set aspnetcore_environment in publish file?
I have ASP.NET Core application (Web Api). The documentation has explained working with multiple environments, however it failed to explain how to set aspnetcore_environment when publishing the web ...
81
votes
7
answers
45k
views
What's the difference between ASP.NET 5, .NET Core, and ASP.NET Core 5? [closed]
I'm confused on the distinction between these terms:
ASP.NET 5 (now renamed ASP.NET Core and released as 1.0, not 5.0)
ASP.NET Core 5
.NET Core
Can anyone briefly explain it?
80
votes
13
answers
56k
views
How to get "Manage User Secrets" in a .NET Core console-application?
When I create a new ASP .NET Core Web-Application, I can right-click the project in Visual Studio, and I see a context-menu entry called "Manage User Secrets".
When I create a new .NET Core Console-...
80
votes
7
answers
156k
views
A fatal error occurred. The required library hostfxr.dll could not be found
When I run my WPF application on other computers it throws me this error:
Description: A .NET Core application failed.
Application: program.exe
Path: C:\fakepath\program.exe
Message: A fatal error ...
80
votes
5
answers
31k
views
Build .exe file in .NET Core RC2
Every time I build a project using the new .NET Core RC2 templates I am not provided with a runnable .EXE file. If I hit F5 for debugging my console application it runs fine through the
C:\Program ...
80
votes
6
answers
48k
views
Is it possible to compile a single C# code file with the .NET Core Roslyn compiler?
In old .NET we used to be able to run the csc compiler to compile a single .cs file or several files.
With .NET Core we have dotnet build that insists on having a proper project file. Is there a ...
79
votes
10
answers
171k
views
How to get access token from HttpContext in .Net core 2.0
I'm trying to upgrade a project from .Net core 1.1 to .Net core 2.0 there's a lot of breaking changes.
One of the things I'm currently having an issue with is that HttpContext.Authentication is now ...
79
votes
5
answers
54k
views
How to get Table Name of mapped entity in Entity Framework Core
In some reason, I need to use SQL in EFCore, and I will use table name of mapped entity. How can I get it?
78
votes
6
answers
89k
views
Add a package with a local package file in 'dotnet'
Using the dotnet command line tool, how can I add a reference to an existing local package that is not downloaded with NuGet?
I have tried adding a local package to a project bar with dotnet:
dotnet ...
78
votes
1
answer
28k
views
Replacement of AssemblyBuilder.DefineDynamicAssembly in .NET Core
How do I port the following code to .NET Core?
AppDomain.CurrentDomain.DefineDynamicAssembly(
new AssemblyName(
Guid.NewGuid().ToString()),
...
78
votes
3
answers
100k
views
How to extract custom header value?
I have this exact code from the accepted answer in my project which I need to migrate into ASP.NET Core MVP.
How to extract custom header value in Web API message handler?
var env = Request.Headers....
78
votes
4
answers
54k
views
How do I reference a .NET Framework project in a .NET Core project?
I'd really like to start using .NET Core and slowly migrate applications and libraries to it. However, I can't realistically upgrade my entire code base to use .NET Core and then go through the ...
78
votes
2
answers
33k
views
What's the difference between the new netstandardapp and netcoreapp TFMs?
I noticed that NuGet has recently added support for several new TFMs related to .NET Core, including:
netstandard (1.0-1.5)
netstandardapp (1.5)
netcoreapp (1.0)
To the best of my knowledge, ...
77
votes
6
answers
118k
views
How to get values from appsettings.json in a console application using .NET Core?
i'm creating a console application using .NET Core 3.1 and i would like to have an appsettings json to load all
environment, paths, variables,... at the beginning of the execution, and then get values ...
77
votes
6
answers
56k
views
Do we need interfaces for dependency injection?
I have an ASP.NET Core application. The application has few helper classes that does some work. Each class has different signature method. I see lot of .net core examples online that create interface ...
77
votes
6
answers
93k
views
Encrypted configuration in ASP.NET Core
With web.config going away, what is the preferred way to store sensitive info (passwords, tokens) in the configurations of a web app built using ASP.NET Core?
Is there a way to automatically get ...
76
votes
4
answers
38k
views
Convert .NET Core 2.0 class libraries to .NET Standard
Is there a way to easily convert a class library targeting .NET Core 2.0 to .NET Standard?
If I understand it correctly, if one wants to maximize the reusability of class libraries in projects ...
76
votes
2
answers
80k
views
Entity Framework Core: How to get the Connection from the DbContext?
I am trying the new Entity Framework Core with MySQL Connector.
I can get a valid DbContext and write into the database so everything has been setup correctly.
I need to get the Connection from ...
75
votes
32
answers
105k
views
Unable to start process dotnet.exe
I am attempting to setup a new work space and transfer all of my projects from my old computer to the new one. However, I am getting this error when I try to run IIS Express:
Unable to start ...
75
votes
4
answers
53k
views
JWT Token authentication, expired tokens still working, .net core Web Api
I'm building a .net core web api.
Preface - I've implemented token authentication as per https://stormpath.com/blog/token-authentication-asp-net-core and https://dev.to/samueleresca/developing-token-...
75
votes
3
answers
63k
views
Equivalent for .HasOptional in Entity Framework Core 1 (EF7)
Consider two classes.
public class File
{
[Key]
public string Id { get; set; }
public string Message_Id { get; set; }
internal Message Message { get; set; }
}
public class Message
...
75
votes
1
answer
22k
views
Why bother with dotnet build before dotnet publish?
Welp. This seems like the type of question where I'll facepalm seeing the answer.
So...
Why bother with dotnet build before doing a dotnet publish?
build automatically does a restore. Cool.
It ...
75
votes
1
answer
40k
views
What does PrivateAssets='All' mean?
When I build my .NET Core (NETStandard v2.0) project I am getting the following warning:
ViewModels: [FodyPackageReference] Fody: The package reference for PropertyChanged.Fody
does not contain ...
75
votes
3
answers
7k
views
Is it possible to access the compressed data before decompression in HttpClient?
I'm working on the Google Cloud Storage .NET client
library. There are three features (between .NET, my client
library, and the Storage service) that are combining in an
unpleasant way:
When ...
74
votes
7
answers
57k
views
Debugging xUnit tests in .NET Core and Visual Studio Code
I'm on a Mac, running .NET Core 1.0 and Visual Studio Code.
I have a console project and a test project. I have setup launch.json so that I can debug the console project.
How do I set up a launch ...
74
votes
7
answers
139k
views
Using IConfiguration in C# Class Library
I am building a class library using C# and Core .NET. I am trying to use configuration from a config.json file. Here are the contents of that file:
config.json
{
"emailAddress":"someone@somewhere....
74
votes
6
answers
41k
views
.Net Core - copy to clipboard?
Is it possible to copy something to the clipboard using .Net Core (in a platform-agnostic way)?
It seems that the Clipboard class is missing, and P/Invoking isn't an option outside of Windows.
Edit: ...
74
votes
3
answers
84k
views
Proper way to register HostedService in ASP.NET Core. AddHostedService vs AddSingleton
What is the proper way to register a custom hosted service in ASP.NET Core 2.1? For example, I have a custom hosted service derived from BackgroundService named MyHostedService. How should I register ...
73
votes
3
answers
19k
views
got error " The "RazorGenerate" task failed unexpectedly. " .After Updating to VS 16.8 and upgrade to .net 5.. the core version target is Core 2.2
When Build Project. Error The "RazorGenerate" task failed unexpectedly. .Net Core 2.2
73
votes
8
answers
52k
views
TimeZoneInfo in .NET Core when hosting on unix (nginx)
For example, when I try to do the following.
TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time")
I get the error, that the TimeZone is not available on the local computer. When I ...
73
votes
6
answers
60k
views
Inject service into Action Filter
I am trying to inject a service into my action filter but I am not getting the required service injected in the constructor. Here is what I have:
public class EnsureUserLoggedIn : ...
73
votes
13
answers
33k
views
Can't read app.config in C# .NET Core unit test project with ConfigurationManager
I've created a simple unit test project to read an app.config file. Target framework is Core 2.0. I also created a Core 2.0 console app, to sanity-check myself to make sure I wasn't doing anything ...
73
votes
1
answer
30k
views
Message template should be compile time constant
I have this code
[HttpGet("average/{videoGuid}")]
public async Task<IActionResult> AverageRatingOfVideo([FromRoute] string videoGuid)
{
_logger.LogInformation($"Finding ...
73
votes
1
answer
48k
views
AddDbContext was called with configuration, but the context type 'MyContext' only declares a parameterless constructor?
In the following console application (.Net core 2.0), the scaffold-dbcontext created the following DbContext
public partial class MyContext : DbContext
{
public virtual DbSet<Tables> Tables ...
73
votes
7
answers
61k
views
How to get IOptions in ConfigureServices method?
I have asp.net core application. I want to use IOptions pattern to inject values from appsettings.json. So I have a class SecurityHeaderOptions, and also have target class SecurityHeadersBuilder whose ...
73
votes
17
answers
127k
views
ASP.NET Core appsettings.json update in code
I am currently working on project using asp.net core v1.1, and in my appsettings.json I have:
"AppSettings": {
"AzureConnectionKey": "***",
"AzureContainerName": "**",
"NumberOfTicks": ...
72
votes
9
answers
32k
views
Does .net core dependency injection support Lazy<T>
I am trying to use the generic Lazy class to instantiate a costly class with .net core dependency injection extension. I have registered the IRepo type, but I'm not sure what the registration of the ...
72
votes
13
answers
91k
views
.NET Core app unable to start in IIS due to ErrorCode = '0x80004005 : 80008083
I have a .NET Core application. It runs locally with VS2017 and Kestrel. It runs locally under IIS. However, on the server it fails to start with a 502.5 - Process Failure message.
In the event logs ...
72
votes
11
answers
130k
views
The NPM script 'start' exited without indicating that the Angular CLI was listening for requests
I'm attempting to start an .NET Core 2/Angular 6 SPA. I created an Angular 5 Application using "dotnet new angular" then proceeded to upgrade using this guide from angular.io. Once I ...
72
votes
9
answers
80k
views
How do you read a simple value out of some json using System.Text.Json?
I have this json
{"id":"48e86841-f62c-42c9-ae20-b54ba8c35d6d"}
How do I get the 48e86841-f62c-42c9-ae20-b54ba8c35d6d out of it? All examples I can find show to do something like
var o = System.Text....
72
votes
11
answers
54k
views
How do I update all NuGet packages at once with the dotnet CLI?
I'm trying to update all NuGet packages for a solution in VS Code (using Mac). Is there a way to achieve that in VS code or for a specific project.json file? At the moment I'm going one by one but I ...