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
        
        
            72
            votes
        
        
            2
            answers
        
        
            20k
            views
        
    Safety of AsyncLocal in ASP.NET Core
                For .NET Core, AsyncLocal is the replacement for CallContext.  However, it is unclear how "safe" it is to use in ASP.NET Core.
In ASP.NET 4 (MVC 5) and earlier, the thread-agility model of ASP.NET ...
            
        
       
    
            71
            votes
        
        
            1
            answer
        
        
            75k
            views
        
    Cascade deleting with EF Core
                I am having a few issues with EF Core at the moment. I have some data that I need to delete, and I am struggeling to see how the fluent API works, exactly in regards to the .OnDelete() function.
...
            
        
       
    
            71
            votes
        
        
            10
            answers
        
        
            107k
            views
        
    Nuget restore fails on Azure Devops with message "unable to load the service index for source"
                I have a build for a .NET solution that is running in a private agent. The solution contains both .NET Core 2.1 and .NET Standard 2.0 projects. 
Some of the nuget packages installed are the following:...
            
        
       
    
            70
            votes
        
        
            14
            answers
        
        
            69k
            views
        
    Where is the PostAsJsonAsync method in ASP.NET Core?
                I was looking for the PostAsJsonAsync() extension method in ASP.NET Core. Based on this article, it's available in the Microsoft.AspNet.WebApi.Client assembly. 
I had thought Microsoft had changed ...
            
        
       
    
            70
            votes
        
        
            13
            answers
        
        
            72k
            views
        
    Enable OPTIONS header for CORS on .NET Core Web API
                I solved this problem after not finding the solution on Stackoverflow, so I am sharing my problem here and the solution in an answer.
After enabling a cross domain policy in my .NET Core Web Api ...
            
        
       
    
            70
            votes
        
        
            8
            answers
        
        
            48k
            views
        
    How to Unit Test with ActionResult<T>?
                I have a xUnit test like:
[Fact]
public async void GetLocationsCountAsync_WhenCalled_ReturnsLocationsCount()
{
    _locationsService.Setup(s => s.GetLocationsCountAsync("123")).ReturnsAsync(10);
  ...
            
        
       
    
            70
            votes
        
        
            11
            answers
        
        
            169k
            views
        
    Postman error: "Unable to verify the first certificate" when try to get from my .net core API
                I have my brand new .NET Core service with API and I want to get list of items inside it. It's hosted on localhost and I always have this error:
16 ms
Warning: Unable to verify the first certificate
...
            
        
       
    
            69
            votes
        
        
            11
            answers
        
        
            73k
            views
        
    Failed to find a valid digest in the 'integrity' attribute for resource in Blazor app
                I have a Blazor client/server app that I have been working on for a period and it has been working fine up to now. I suddenly started getting this error
Failed to find a valid digest in the '...
            
        
       
    
            69
            votes
        
        
            1
            answer
        
        
            58k
            views
        
    Difference between AllowedHosts in appsettings.json and UseCors in .NET Core API 3.x
                I see that .NET Core 3.x comes with a new special configuration AllowedHosts used to list hosts allowed to access the site while this option already exists with CORS (app.UseCors).
What's the ...
            
        
       
    
            69
            votes
        
        
            4
            answers
        
        
            101k
            views
        
    How to run all tests in Visual Studio Code
                The latest version of VS Code already provides an easy way of running a single test as pointed on Tyler Long's answer to the question Debugging xunit tests in .NET Core and Visual Studio Code.
However,...
            
        
       
    
            68
            votes
        
        
            14
            answers
        
        
            119k
            views
        
    EF Core Error - No project was found. Change the current working directory or use the --project option
                I am using Visual Studio 2015 and dotnet core and trying to develop an EF Core Code First project using Sqlite and this documentation / tutorial, which also uses Sqlite => NET Core - New Database
...
            
        
       
    
            68
            votes
        
        
            3
            answers
        
        
            15k
            views
        
    No UseDatabaseErrorPage() extension method in Net Core 3.0
                I have created Net Core 3.0 app and following code that worked in 2.2 now is not.
app.UseDatabaseErrorPage();
Looks like in 3.0 class DatabaseErrorPageExtensions does not exist within Microsoft....
            
        
       
    
            68
            votes
        
        
            11
            answers
        
        
            82k
            views
        
    Error: It was not possible to find any installed .NET Core SDKs
                When I run the command docker run -i -t myProject it shows error: 
  It was not possible to find any installed .NET Core SDKs
    Did you mean to run .NET Core SDK commands? Install a .NET Core SDK ...
            
        
       
    
            68
            votes
        
        
            15
            answers
        
        
            51k
            views
        
    Looking for simple rules-engine library in .NET [closed]
                Does anyone know of a good .NET library rules library (ideally open-source)?  I need something that can do nested logic expressions, e.g., (A AND B) AND (B OR C OR D).  I need to do comparisons of ...
            
        
       
    
            68
            votes
        
        
            1
            answer
        
        
            36k
            views
        
    Which web server are you using in production for ASP.NET Core on a *nix server?
                With ASP.NET Core now released, I was wondering what the best hosting option is for Linux and Mac environments. Is there any production grade web server under active development?
The only one I'm ...
            
        
       
    
            67
            votes
        
        
            7
            answers
        
        
            18k
            views
        
    Problems installing Dot Net Core 1.0.0 VS 2015 Tools Preview 2
                Each time I try to install the DotNetCore.1.0.0-VS2015Tools.Preview2.exe package I get an error saying the following:
  Setup Failed One or more issues caused the setup to fail.  Please fix
  the ...
            
        
       
    
            67
            votes
        
        
            2
            answers
        
        
            67k
            views
        
    System.Text.Json: How do I specify a custom name for an enum value?
                Using the System.Text.Json serializer capabilities in .NET Core, how can I specify a custom value for an enum value, similar to JsonPropertyName? For example:
public enum Example {
  Trick, 
  Treat, ...
            
        
       
    
            67
            votes
        
        
            7
            answers
        
        
            160k
            views
        
    How do I resolve the issue the request matched multiple endpoints in .Net Core Web Api
                I notice that there are a bunch of similar questions out there about this topic. 
I'm getting this error when calling any of the methods below.
  Microsoft.AspNetCore.Routing.Matching....
            
        
       
    
            67
            votes
        
        
            5
            answers
        
        
            60k
            views
        
    Use Serilog with Microsoft.Extensions.Logging.ILogger
                I've created a .NET Core 3.1 project using a Host, the IoC container with IServiceCollection and implemented logging allover the place using the ILogger<T> interface from Microsoft.Extensions....
            
        
       
    
            67
            votes
        
        
            7
            answers
        
        
            42k
            views
        
    Is there a way to format the output format in .NET Core logging?
                I'm using the built in logging provider for logging into the console  (Microsoft.Extensions.Logging.Console) in a .NET Core console application.
Each logging entry produces two lines in the output. I ...
            
        
       
    
            67
            votes
        
        
            3
            answers
        
        
            39k
            views
        
    .Net Core and NuGet
                I installed .net core from this site.  Playing with it led to a number of related package management questions:
The dotnet restore command proceeded to "install" .net core NuGet packages.  Where were ...
            
        
       
    
            67
            votes
        
        
            1
            answer
        
        
            3k
            views
        
    Why are three properties in DbParameterCollection abstract in reference assemblies but virtual otherwise?
                I'm moving a project from project.json to the new-style csproj format, and it includes a class derived from DbParameterCollection. In my real project I'm using multi-targeting, but for the purposes of ...
            
        
       
    
            66
            votes
        
        
            7
            answers
        
        
            43k
            views
        
    How to fix obsolete ILoggerFactory methods?
                I upgraded my project to .NET Core 2.2.x and got an obsolete warning regarding the following code - both lines:
public void Configure(IApplicationBuilder app, 
                      ...
            
        
       
    
            66
            votes
        
        
            7
            answers
        
        
            113k
            views
        
    Access from class library to appsetting.json in Asp.net-core
                I am trying to access appsetting.json file from a class library. So far the solution that I found is to create a configuration class implementing interface IConfiguration from  Microsoft.Extensions....
            
        
       
    
            66
            votes
        
        
            1
            answer
        
        
            18k
            views
        
    Upgrading to .NET Core 2.0: PackageTargetFallback and AssetTargetFallback cannot be used together
                When upgrading a project that is compiling and running fine on .NET Core 1.0 or 1.1, updating the target framework to .NET Core 2.0 (netcoreapp2.0) causes the build to fail with the following error:
 ...
            
        
       
    
            65
            votes
        
        
            5
            answers
        
        
            51k
            views
        
    How to set .NET Core in #if statement for compilation
                I created a multi-targeted framework project. I use something like this:
  #if NET40
    Console.WriteLine("Hello from .NET Core 4");
  #endif
But I can't find a wildcard for .NET Core. I tried:
   ...
            
        
       
    
            65
            votes
        
        
            2
            answers
        
        
            27k
            views
        
    Difference between .NET Framework 4.6, .Net Native and .Net Core [closed]
                I see the following in almost every future .NET framework discussion:
.NET Framework 4.6 (Full .Net framework)
.NET Native
.NET Core
What is the difference between all of these? 
How do I know when ...
            
        
       
    
            65
            votes
        
        
            4
            answers
        
        
            170k
            views
        
    Reference external DLL in .NET Core project
                I've my own .dll file that I used to use with Edge.js in nodejs,
I'm trying to use it now with dot net core app, but found no where/no how to get access to it, or define it.
is there something like 
...
            
        
       
    
            65
            votes
        
        
            3
            answers
        
        
            21k
            views
        
    How is the new C# Span<T> different from ArraySegment<T>?
                I am having trouble conceptualizing the usages for the new Span<T> in C#.
What construct(s) does it replace? Is ArraySegment<T> now obsolete?
What functionality does it enable that ...
            
        
       
    
            65
            votes
        
        
            6
            answers
        
        
            199k
            views
        
    How do I add assembly references in Visual Studio Code?
                So I've come across a similar issue twice now while working on my first project in C#.  When trying to add either using System.Data; or using System.Timers;, I get the following error:
  The type or ...
            
        
       
    
            65
            votes
        
        
            3
            answers
        
        
            48k
            views
        
    Filter Serilog logs to different sinks depending on context source?
                I have a .NET Core 2.0 application in which I successfully use Serilog for logging. Now, I would like to log some database performance statistics to a separate sink (they are not for debugging, which ...
            
        
       
    
            64
            votes
        
        
            8
            answers
        
        
            32k
            views
        
    Build error while transitioning between branches: Your project is not referencing the ".NETFramework,Version=v4.7.2" framework
                We're using Git and we have a solution which is targeting the full net framework. A couple of days ago, I've started migrating the solution to .net core. Unfortunately, something comes up which made ...
            
        
       
    
            64
            votes
        
        
            16
            answers
        
        
            141k
            views
        
    Failed to bind to address (already in use) error with Visual Studio Mac API
                I'm attempting to create a Web API via .Net Core. I'm just using the boilerplate ValuesController as a Hello World. When I run the project, I get the following error:
System.IO.IOException: "Failed ...
            
        
       
    
            64
            votes
        
        
            11
            answers
        
        
            109k
            views
        
    Get List<> element position in c# using LINQ
                I have a List with numbers,
and I'd like to find the position of the minimum (not value) using LINQ
Example:
var lst = new List<int>() { 3, 1, 0, 5 };
Now I am looking for a function returning ...
            
        
       
    
            64
            votes
        
        
            10
            answers
        
        
            87k
            views
        
    CORS in .NET Core
                I am trying to enable CORS in .NET Core in this way:
    public IConfigurationRoot Configuration { get; }
    public void ConfigureServices(IServiceCollection services)
    {
        services....
            
        
       
    
            64
            votes
        
        
            3
            answers
        
        
            44k
            views
        
    Should GetEnvironmentVariable work in xUnit tests?
                If I set environment variables for a .Net Core web project in Visual Studio 2017 using the project properties page, I can read the value of the variable using Environment.GetEnvironmentVariable; ...
            
        
       
    
            64
            votes
        
        
            9
            answers
        
        
            108k
            views
        
    Receive file and other form data together in ASP.NET Core Web API (boundary based request parsing)
                How would you form your parameters for the action method which is supposed to receive one file and one text value from the request?
I tried this
public string Post([FromBody]string name, [FromBody]...
            
        
       
    
            64
            votes
        
        
            8
            answers
        
        
            49k
            views
        
    dotnet publish with /p:PublishProfile=?
                I'm trying to call "dotnet publish" with a specific publish profile pubxml file as documented here :
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=...
            
        
       
    
            64
            votes
        
        
            9
            answers
        
        
            35k
            views
        
    Is it possible to run a .NET Core console application silently (hide console window)?
                I'm trying to automate some tasks for myself and I wrote a few .NET Core 1.0 console applications. One of them is BrowserRouter - a simple application which, based on a URL pattern, decides which ...
            
        
       
    
            63
            votes
        
        
            13
            answers
        
        
            25k
            views
        
    No executables found matching command 'dotnet-aspnet-codegenerator'"
                When trying to add a Controller in an ASP.NET Core project using Visual Studio 15 Enterprise with Update 3, I get the error below: 
"The was an error running the selected code generator: No ...
            
        
       
    
            63
            votes
        
        
            10
            answers
        
        
            57k
            views
        
    Error in Visual Studio Code Dotnet Core C#: "The type or namespace name 'System' could not be found", but build succeeds
                When trying to work with Visual Studio Code on a C# DotNet Core MVC application, I am having a lot of trouble getting visual studio code to work. It is having trouble finding anything related to C#, ...
            
        
       
    
            63
            votes
        
        
            5
            answers
        
        
            34k
            views
        
    Access to configuration without dependency injection
                I was wondering if there was a way to access Configuration (Microsoft.Extensions.Configuration) without the use of dependency injection.  Only examples I see are through constructor injection (using ...
            
        
       
    
            63
            votes
        
        
            1
            answer
        
        
            10k
            views
        
    Dotnet Core Docker Container Leaks RAM on Linux and causes OOM
                I am running Dotnet Core 2.2 in a Linux container in Docker.
I've tried many different configuration/environment options - but I keep coming back to the same problem of running out of memory ('docker ...
            
        
       
    
            62
            votes
        
        
            2
            answers
        
        
            63k
            views
        
    How to run .NET Core Console app using generic host builder
                I am trying to figure out how to use hostbuilder pattern to run a console app (not a windows service). Intent is to keep the flow as similar to a WebApi to keep development practices similar. I have ...
            
        
       
    
            62
            votes
        
        
            3
            answers
        
        
            65k
            views
        
    Unable to resolve service for type 'System.String' while attempting to activate 'MyService'
                I'm seeing the following exception in my Service Fabric Stateless ASP.NET Core app.
System.InvalidOperationException: Unable to resolve service for type 'System.String' while attempting to activate '...
            
        
       
    
            61
            votes
        
        
            3
            answers
        
        
            75k
            views
        
    Nuget - Package restore failed. Rolling back package changes for 'WebApplication1'. 0
                It's my own custom nuget package that I've not published yet and testing locally.
The nuget package consists of a dll file and nuspec file is as follows.
<?xml version="1.0"?>
<package >
...
            
        
       
    
            61
            votes
        
        
            9
            answers
        
        
            70k
            views
        
    You must add a reference to assembly mscorlib, version=4.0.0
                I'm having some trouble migrating a web project from RC1 to RC2. When I switched, I'm getting a bunch of these errors throughout the project.
  The type 'Func<,>' is defined in an assembly that is ...
            
        
       
    
            61
            votes
        
        
            9
            answers
        
        
            62k
            views
        
    Cross-platform file name handling in .NET Core
                How to handle file name in System.IO classes in a cross-platform manner to make it work on Windows and Linux?
For example, I write this code that works perfectly on Windows, however it doesn't create ...
            
        
       
    
            61
            votes
        
        
            22
            answers
        
        
            55k
            views
        
    System could not be found Visual Studio 2017 ASP.NET Core project
                I've installed the newly released version of Visual Studio 2017 and started a fresh ASP.NET Core project targeting .NET Core.
Out of the box, I'm getting the 
  The type or namespace name 'System' ...
            
        
       
    
            61
            votes
        
        
            1
            answer
        
        
            26k
            views
        
    How to determine if service has already been added to IServiceCollection
                I am creating helper classes to simplify configuration and injection of interfaces via IServiceCollection for a library. The libraries constructor contains a number of dependencies that are likely to ...