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,031
            questions
        
        
            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 ...
            
        
       
    
            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> - ...
            
        
       
    
            105
            votes
        
        
            12
            answers
        
        
            147k
            views
        
    .NET Core console application, how to configure appSettings per environment?
                I have a .NET Core 1.0.0 console application and two environments. I need to be able to use appSettings.dev.json and appSettings.test.json based on environment variables I set at run time. This seems ...
            
        
       
    
            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 ...
            
        
       
    
            102
            votes
        
        
            5
            answers
        
        
            55k
            views
        
    error CS8773: "Feature 'global using directive' is not available in C# 9.0" after downgrade from net6.0 to net5.0
                I have a project that was initially created for .NET 6 but then I needed to downgrade it to .NET 5.
I changed Target framework in Project Properties and tried to compile. As a result I received a ...
            
        
       
    
            102
            votes
        
        
            24
            answers
        
        
            140k
            views
        
    Is there an easy way to check the .NET Framework version?
                The problem is that I need to know if it's version 3.5 SP 1. Environment.Version() only returns 2.0.50727.3053.
I found this solution, but I think it will take much more time than it's worth, so I'm ...
            
        
       
    
            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 ...
            
        
       
    
            101
            votes
        
        
            3
            answers
        
        
            7k
            views
        
    What are the application implications of a netstandard library depending on a metapackage?
                Suppose I have a class library which I want to target netstandard1.3, but also use BigInteger. Here's a trivial example - the sole source file is Adder.cs:
using System;
using System.Numerics;
...
            
        
       
    
            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": [
   ...
            
        
       
    
            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 ...
            
        
       
    
            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 ...
            
        
       
    
            100
            votes
        
        
            4
            answers
        
        
            54k
            views
        
    AssemblyVersion using * fails with error "wildcards, which are not compatible with determinism?"
                I can't use * in assembly version; when I do I get the following compilation error:
The specified version string contains wildcards, which are not
compatible with determinism. Either remove wildcards ...
            
        
       
    
            99
            votes
        
        
            4
            answers
        
        
            57k
            views
        
    dotnet core System.Text.Json unescape unicode string
                Using JsonSerializer.Serialize(obj) will produce an escaped string, but I want the unescaped version. For example:
using System;
using System.Text.Json;
public class Program
{
    public static void ...
            
        
       
    
            99
            votes
        
        
            1
            answer
        
        
            178k
            views
        
    How to run a .NET Core console application on Linux [duplicate]
                I am using Visual Studio 2015 and created a .NET Core console application. After compiling, I have my project DLL file in the debug folder. And if I want to run it on another computer, I have to ...
            
        
       
    
            99
            votes
        
        
            2
            answers
        
        
            39k
            views
        
    How do I run specific tests using dotnet test?
                I have a large test suite in a .NET Core project. I can use the Test Explorer window to select a few tests to run.
I can also run the whole test suite on the command line with dotnet test. Is there a ...
            
        
       
    
            97
            votes
        
        
            6
            answers
        
        
            63k
            views
        
    ef core doesn't use ASPNETCORE_ENVIRONMENT during update-database
                I use visual studio to update all my environments with a certain migration. It had worked fine using the command below.
update-database -Migration initMigrationProduct -c ProductContext -Environment ...
            
        
       
    
            97
            votes
        
        
            5
            answers
        
        
            80k
            views
        
    'IHostingEnvironment' is obsolete
                I updated my ASP.NET Core project to .NET Core v3.0.0-preview3, and I now get:
  Startup.cs(75,50,75,69): warning CS0618: 'IHostingEnvironment' is
  obsolete: 'This type is obsolete and will be ...
            
        
       
    
            97
            votes
        
        
            9
            answers
        
        
            22k
            views
        
    The author primary signature's timestamp found a chain building issue: UntrustedRoot: self signed certificate in certificate chain
                While doing a docker build on my .NET Core project, I got the following error on all my NuGets:
80.19 /app/GradingTool.Tests/GradingTool.Tests.csproj : error NU3028: Package 'Microsoft....
            
        
       
    
            96
            votes
        
        
            12
            answers
        
        
            130k
            views
        
    HTTP Error 500.19 when publish .net core project into iis with 0x80070005
                I want to publish a sample .net core web application on my pc's IIS manager but I failed. I am using Microsoft guidance but it doesn't work for me, if you have reasonable experience to fix this ...
            
        
       
    
            96
            votes
        
        
            4
            answers
        
        
            58k
            views
        
    Package version is always 1.0.0 with dotnet pack
                TLDR: Where is dotnet pack pulling the version information when it creates the nuget package for an assembly?  
I have a library, that I had transitioned from a .NET 4.6.1 project to a .NET Core ...
            
        
       
    
            96
            votes
        
        
            9
            answers
        
        
            130k
            views
        
    Convert Word doc and docx format to PDF in .NET Core without Microsoft.Office.Interop
                I need to display Word .doc and .docx files in a browser. There's no real client-side way to do this and these documents can't be shared with Google docs or Microsoft Office 365 for legal reasons.
...
            
        
       
    
            96
            votes
        
        
            4
            answers
        
        
            69k
            views
        
    dotnet restore warning NU1701
                I am using .NET Core with C#, and when I did dotnet restore, it gave the following error:
PS C:\workspace\Arbitrator> dotnet restore
C:\workspace\Arbitrator\Arbitrator.csproj : warning NU1701: ...
            
        
       
    
            96
            votes
        
        
            4
            answers
        
        
            60k
            views
        
    How to create a LoggerFactory with a ConsoleLoggerProvider?
                The ConsoleLoggerProvider has four constructors:
ConsoleLoggerProvider(IConsoleLoggerSettings)
ConsoleLoggerProvider(IOptionsMonitor<ConsoleLoggerOptions>)
ConsoleLoggerProvider(Func<String,...
            
        
       
    
            96
            votes
        
        
            9
            answers
        
        
            213k
            views
        
    Add client certificate to .NET Core HttpClient
                I was playing around with .NET Core and building an API that utilizes payment APIs. There's a client certificate that needs to be added to the request for two-way SSL authentication.
How can I achieve ...
            
        
       
    
            95
            votes
        
        
            9
            answers
        
        
            80k
            views
        
    Suppress SQL Queries logging in Entity Framework core
                I have a console .net core app that uses entity framework core.
The app uses logging framework to write to file and console:
 serviceProvider = new ServiceCollection()
        .AddLogging()
        ....
            
        
       
    
            95
            votes
        
        
            4
            answers
        
        
            204k
            views
        
    Using app.config in .Net Core
                I have problem. I need to write a program in .Net Core(C#) which use app.config like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section ...
            
        
       
    
            94
            votes
        
        
            15
            answers
        
        
            72k
            views
        
    .NET Core: Remove null fields from API JSON response
                On a global level in .NET Core 1.0 (all API responses), how can I configure Startup.cs so that null fields are removed/ignored in JSON responses?
Using Newtonsoft.Json, you can apply the following ...
            
        
       
    
            94
            votes
        
        
            4
            answers
        
        
            18k
            views
        
    How do I get a console project to group my appsettings.json files?
                If I start a new web api project, the appsettings files are grouped together. However, I'm creating a working project from the console app template and when I create the appsettings files manually, ...
            
        
       
    
            94
            votes
        
        
            7
            answers
        
        
            54k
            views
        
    Using Razor outside of MVC in .NET Core
                I would like to use Razor as a templating engine in a .NET console application that I'm writing in .NET Core.
The standalone Razor engines I've come across (RazorEngine, RazorTemplates) all require ...
            
        
       
    
            94
            votes
        
        
            5
            answers
        
        
            12k
            views
        
    Can files be nested in VS2017 Solution Explorer for .NET Core (non-ASP.NET Core) projects?
                In "old school" MSBuild projects - as still used by Windows Forms in VS2017 for example - files could be "nested" via a DependentUpon item in the csproj file.
I used this to group unit tests together ...
            
        
       
    
            94
            votes
        
        
            5
            answers
        
        
            17k
            views
        
    Visual Studio 2017 install breaks Visual Studio 2015 ASP.NET Core Projects
                After installing Visual Studio 2017 Professional I can't build my ASP.NET Core in Visual Studio 2015 Professional anymore. I never opened this project in VS2017
I get
The following error occured ...
            
        
       
    
            94
            votes
        
        
            1
            answer
        
        
            38k
            views
        
    What does <None Remove="..." /> mean in csproj?
                I'm working with a dotnet core csproj and I've added a new file. It doesn't initially get added to the csproj at all because of convention over configuration. But as soon as I change its Build Action ...
            
        
       
    
            93
            votes
        
        
            11
            answers
        
        
            64k
            views
        
    'ILoggerFactory' does not contain a definition for 'AddConsole'
                private ILoggerFactory ConfigureLogging(ILoggerFactory factory)
{
      factory.AddConsole();
      return factory;
}
I have found the piece of  code above on Github. It gives the following error:
'...
            
        
       
    
            93
            votes
        
        
            7
            answers
        
        
            99k
            views
        
    How can I pass a runtime parameter as part of the dependency resolution?
                I need to be able to pass a connection string into some of my service implementations. I am doing this in the constructor. The connection string is configurable by user will be added the ...
            
        
       
    
            92
            votes
        
        
            10
            answers
        
        
            119k
            views
        
    Microsoft Visual Studio 2019: The project file cannot be opened. Unable to locate the .NET SDK
                I just upgraded my visual studio 2019 to latest version 16.8.3 and suddenly I am not able to load any C# project and getting the following error for all .NET core projects:
The project file cannot be ...
            
        
       
    
            92
            votes
        
        
            11
            answers
        
        
            73k
            views
        
    Moq IServiceProvider / IServiceScope
                I am trying to create a Mock (using Moq) for an IServiceProvider so that I can test my repository class:
public class ApiResourceRepository : IApiResourceRepository
{
    private readonly ...
            
        
       
    
            91
            votes
        
        
            10
            answers
        
        
            200k
            views
        
    Cannot access a disposed object. A common cause of this error is disposing a context
                I have written a simple application and when I navigate to my edit page the below error pops up.
Microsoft.EntityFrameworkCore.Query[10100]
An exception occurred while iterating over the results of ...
            
        
       
    
            89
            votes
        
        
            9
            answers
        
        
            87k
            views
        
    dotnet publish doesn´t publish correct appsettings.{env.EnvironmentName}.json
                When I issue the following command in the command line:
dotnet publish -o "./../output" -c Release
The dotnetcli publishes the project correctly. However, it does not copy the appsettings.Production....
            
        
       
    
            89
            votes
        
        
            4
            answers
        
        
            40k
            views
        
    Why isn't there any packages folder in my .NET Core solution's containing folder?
                Are packages now cached in a more shared location somewhere or what?
My solution folder is devoid of any packages folder:
            
        
       
    
            89
            votes
        
        
            3
            answers
        
        
            23k
            views
        
    Should HttpClient instances created by HttpClientFactory be disposed?
                So, I've registered a named client with the services collection in my Startup.cs:
services.AddHttpClient(someServiceName, 
                       client => client.BaseAddress = baseAddress);
and ...
            
        
       
    
            88
            votes
        
        
            18
            answers
        
        
            178k
            views
        
    Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0
                After update to the new package Microsoft.EntityFrameworkCore.SqlServer 1.1.2  I got error when try to create DBContext:
  System.IO.FileLoadException occurred   HResult=0x80131040
  Message=Could ...
            
        
       
    
            87
            votes
        
        
            4
            answers
        
        
            121k
            views
        
    How to instantiate a DbContext in EF Core
                I have setup .net core project and db context also. But i cant start using dbContext yet due this error-
"there is no argument given that corresponds to the required formal
parameter 'options'&...
            
        
       
    
            87
            votes
        
        
            18
            answers
        
        
            102k
            views
        
    ASP.NET Core 3.0 not showing on Visual Studio 2019
                I want to test the new Blazor server-side framework (aka Razor Components).
I installed Visual Studio 2019 RC, and then the .Net Core 3.0 preview 2, following this official tutorial.
After the ...
            
        
       
    
            86
            votes
        
        
            4
            answers
        
        
            77k
            views
        
    Can WPF applications be run in Linux or Mac with .Net Core 3?
                Microsoft announced .NET Core 3 comes with WPF and Windows Forms. So can I create a desktop application for Linux or Mac using .NET Core 3?
            
        
       
    
            85
            votes
        
        
            5
            answers
        
        
            40k
            views
        
    Compile a .NET Core application as an EXE file using Visual Studio 2017
                I created a .NET Core application (v1.1) in Visual Studio 2017. When I compile it, I get a DLL file produced instead of the expected EXE file for the built project. I did check the csproj file and ...
            
        
       
    
            85
            votes
        
        
            6
            answers
        
        
            69k
            views
        
    JWT on .NET Core 2.0
                I've been on quite an adventure to get JWT working on DotNet core 2.0 (now reaching final release today).  There is a ton of documentation, but all the sample code seems to be using deprecated APIs ...
            
        
       
    
            85
            votes
        
        
            3
            answers
        
        
            25k
            views
        
    Difference between ASP.NET Core (.NET Core) and ASP.NET Core (.NET Framework)
                What is the difference between ASP.NET Core Web (.NET Core) vs ASP.NET Core Web (.NET Framework)?
and does .NET Framework provide similar performance as to .NET Core?
            
        
       
    
            85
            votes
        
        
            12
            answers
        
        
            69k
            views
        
    How to globally set default options for System.Text.Json.JsonSerializer?
                Instead of this:
JsonSerializerOptions options = new JsonSerializerOptions
{
    PropertyNamingPolicy = JsonNamingPolicy.CamelCase
    // etc.
};
var so = JsonSerializer.Deserialize<SomeObject>(...
            
        
       
    
            85
            votes
        
        
            4
            answers
        
        
            59k
            views
        
    Manipulating images with .NET Core
                I have updated my project from .NET 4.5 to .NET Core (with ASP.NET Core). I had some very simple code in my previous version that used the bitmap object from System.Drawing to resize an image.
As I ...
            
        
       
    
            85
            votes
        
        
            2
            answers
        
        
            5k
            views
        
    Why is code behavior different in release & debug mode?
                Consider the following code:
private static void Main(string[] args)
{
    var ar = new double[]
    {
        100
    };
    FillTo(ref ar, 5);
    Console.WriteLine(string.Join(",", ar.Select(a =&...