All Questions

Tagged with
Filter by
Sorted by
Tagged with
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 ...
Elvin Mammadov's user avatar
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 ...
Konrad Viltersten's user avatar
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 '...
nam's user avatar
  • 23k
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 ...
Oluwafemi's user avatar
  • 14.6k
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 ....
weloytty's user avatar
  • 5,918
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 ...
HaBo's user avatar
  • 14.2k
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 ...
blubberbo's user avatar
  • 4,523
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 ...
user1620696's user avatar
  • 11.1k
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 ...
Nick Mehrdad Babaki's user avatar
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 ...
user avatar
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.
Balanjaneyulu K's user avatar
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 ...
kevskree's user avatar
  • 4,512
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 ...
meds's user avatar
  • 22.5k
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> ...
Jan Kruse's user avatar
  • 2,675
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 ...
Padhraic's user avatar
  • 5,342
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 ...
Roman Kolesnikov's user avatar
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 ...
David Pine's user avatar
  • 24.1k
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 ...
cilerler's user avatar
  • 9,230
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 ...
Sajed's user avatar
  • 1,886
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 ...
Jay's user avatar
  • 9,851
144 votes
17 answers
229k views

Entity Framework Core: `SqlNullValueException: Data is Null.` How to troubleshoot?

I am using Entity Framework Core in an ASP.NET Core application and Controller action and I haven't changed something to the working code nor to the database but I can't tell what is the query ...
Natalie Perret's user avatar
144 votes
5 answers
68k views

How to consume a Scoped service from a Singleton?

How should I inject (using .NET Core's built-in dependency injection library, MS.DI) a DbContext instance into a Singleton? In my specific case the singleton is an IHostedService? What have I tried I ...
Shoe's user avatar
  • 75.6k
139 votes
6 answers
128k views

How to extract a list from appsettings.json in .net core

I have an appsettings.json file which looks like this: { "someSetting": { "subSettings": [ "one", "two", "three" ] } } When I build my ...
devlife's user avatar
  • 15.7k
132 votes
11 answers
117k views

Upload files and JSON in ASP.NET Core Web API

How can I upload a list of files (images) and json data to ASP.NET Core Web API controller using multipart upload? I can successfully receive a list of files, uploaded with multipart/form-data ...
Andrius's user avatar
  • 2,322
128 votes
26 answers
296k views

How to change the port number for Asp.Net core app?

I added the following section in project.json. "commands": { "run": "run server.urls=http://localhost:8082", "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --...
ca9163d9's user avatar
  • 28.3k
126 votes
7 answers
133k views

Switch between dotnet core SDK versions

I recently installed VS 2017 RC and then automatically my dotnet version pointed to 1.0.0-preview4-004233. Due to that whenever I create a new project using command dotnet new -t Console I cannot see ...
Avi Kenjale's user avatar
  • 2,564
126 votes
4 answers
104k views

.NET Core IServiceScopeFactory.CreateScope() vs IServiceProvider.CreateScope() extension

My understanding is that when using the built in the dependency injection, a .NET Core console app will require you to create and manage all scopes yourself whereas a ASP.NET Core app will create and ...
Connie King's user avatar
  • 1,261
125 votes
14 answers
122k views

How to load appsetting.json section into Dictionary in .NET Core?

I am familiar with loading an appsettings.json section into a strongly typed object in .NET Core Startup.cs. For example: public class CustomSection { public int A {get;set;} public int B {get;...
ChrisP's user avatar
  • 9,986
123 votes
3 answers
73k views

'ConfigurationBuilder' does not contain a definition for 'AddJsonFile'

I have the following error: Program.cs(15,72): error CS1061: 'ConfigurationBuilder' does not contain a definition for 'AddJsonFile' and no accessible extension method 'AddJsonFile' accepting a first ...
Luis Valencia's user avatar
122 votes
6 answers
168k views

How to set json serializer settings in asp.net core 3?

json serializer settings for legacy asp.net core applications were set by adding AddMvc().AddJsonOptions(), but I don't use AddMvc() in asp.net core 3. So how can I set global json serialization ...
Alex Zaitsev's user avatar
  • 2,626
121 votes
3 answers
175k views

How to use SqlClient in ASP.NET Core?

I am trying to use SQLClient library in the ASP.net Core but cant seem to get it working. I found this article online advising how to setup but its not working for me: http://blog.developers.ba/using-...
Rob's user avatar
  • 6,969
121 votes
2 answers
20k views

On IServiceProvider what are the differences between the GetRequiredService and GetService methods?

What are the differences between IServiceProvider.GetRequiredService() and IServiceProvider.GetService()? When is it a better idea to use GetRequiredService()?
Art Base's user avatar
  • 1,789
118 votes
4 answers
34k views

"The project 'Web' must provide a value for Configuration" error after migrating to .NET Core 3

I've migrated an ASP.NET Core 2.2 project to Core 3.0 and am getting the error: The project [Project location] must provide a value for Configuration. There's not really a lot to go on with that ...
tomRedox's user avatar
  • 29.1k
118 votes
6 answers
85k views

Dependency Injection with classes other than a Controller class

At this point I'm injecting things into my Controllers with ease, in some cases building my own ResolverServices class. Life is good. What I cannot figure out how to do is get the framework to ...
Robert Paulsen's user avatar
117 votes
39 answers
259k views

EF Core add-migration Build Failed

I have a developer that is getting "Build failed." when running add-migration in a .NET Core EF project, with no explanation of why the build failed. How do you troubleshoot this error? This is what ...
jceddy's user avatar
  • 1,789
116 votes
1 answer
45k views

.NET Core - When to use "dotnet new sln"

I'm a bit confused - the majority of .NET Core tutorials I have been reading have not mentioned "dotnet new sln" - they always just create the projects separately without any solution file to link ...
AndyNZ's user avatar
  • 2,223
115 votes
14 answers
115k views

Cannot find command 'dotnet ef'

I am using .NET Core 2.0 on Arch Linux / Visual Studio Code and am trying to get EF tools to work, but I keep getting the error: cannot find command dotnet ef I've just about looked everywhere and ...
Wasiim Ouro-sama's user avatar
115 votes
12 answers
97k views

Return View as String in .NET Core

I found some article how to return view to string in ASP.NET, but could not covert any to be able to run it with .NET Core public static string RenderViewToString(this Controller controller, string ...
Hasan A Yousef's user avatar
115 votes
15 answers
104k views

Configuration.GetSection always returns Value property null

Every time I call Configuration.GetSection, the Value property of the returned object is always null. My Startup constructor public Startup(IHostingEnvironment env) { var builder = new ...
Liam Mueller's user avatar
  • 1,410
112 votes
1 answer
40k views

How to override ASP.NET Core configuration array settings using environment variables

TL;DR In an ASP.NET Core app, I have an appsettings.json config file which uses a JSON array to configure a collection of settings. How do I override a setting of one of the array objects using ...
James Skimming's user avatar
111 votes
7 answers
79k views

Populate IConfiguration for unit tests

.NET Core configuration allows so many options to add values (environment variables, json files, command line args). I just can't figure out and find an answer how to populate it via code. I am ...
monty's user avatar
  • 8,265
109 votes
8 answers
99k views

No service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' has been registered

What is the possible cause of this error: InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.UserManager [Microsoft.AspNetCore.Identity.IdentityUser]' has been registered....
David Zagi's user avatar
  • 1,423
108 votes
5 answers
148k views

Command line to install/upgrade .NET Core

Are there command line commands to install or upgrade .NET Core? I checked to see if I had .NET Core was installed on my computer using dotnet --version only to notice that I still had the preview ...
Sam's user avatar
  • 28.4k
107 votes
5 answers
75k views

Replace service registration in ASP.NET Core built-in DI container?

Let us consider a service registration in Startup.ConfigureServices: public void ConfigureServices(IServiceCollection services) { services.AddTransient<IFoo, FooA>(); } Is it possible to ...
Ilya Chumakov's user avatar
106 votes
1 answer
46k views

When are .NET Core dependency injected instances disposed?

ASP.NET Core uses extension methods on IServiceCollection to set up dependency injection, then when a type is needed it uses the appropriate method to create a new instance: AddTransient<T> - ...
Keith's user avatar
  • 152k
105 votes
4 answers
76k views

Net Core API: Purpose of ProducesResponseType

I want to understand the purpose of ProducesResponseType. Microsoft defines as: a filter that specifies the type of the value and status code returned by the action. So I am curious what are ...
user avatar
102 votes
6 answers
90k views

Unit testing controller methods which return IActionResult

I'm in the process of building an ASP.NET Core WebAPI and I'm attempting to write unit tests for the controllers. Most examples I've found are from the older WebAPI/WebAPI2 platforms and don't seem ...
Jake Shakesworth's user avatar
101 votes
17 answers
85k views

How to publish environment specific appsettings in .Net core app?

I have 3 environment specific appsettings files in my .Net core application in project.json I have setup publishOptions like this. ( based on suggestion here) "publishOptions": { "include": [ ...
LP13's user avatar
  • 32.3k
100 votes
7 answers
100k views

dotnet run OR dotnet watch with development environment from command line?

I am using dotnet watch command to run asp.net core project. However, by default, it is picking up the Production as an environment. I have tried both options using: 1) > dotnet watch ...
Nexus23's user avatar
  • 6,275
100 votes
6 answers
121k views

Embedded resource in .Net Core libraries

I just have started looking into .Net Core, and I don't see classical resources and anything what looks like resources. In classical .Net class libraries I was able to add, for example, text filtes ...
Don Tomato's user avatar
  • 3,401

1
2 3 4 5
178