All Questions

Tagged with
Filter by
Sorted by
Tagged with
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 ...
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 ...
Gigi's user avatar
  • 28.8k
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 ...
configurator's user avatar
  • 41.2k
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 ...
MeeChao's user avatar
  • 4,327
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 ...
Petr Abdulin's user avatar
  • 34.5k
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 ...
Captainlonate's user avatar
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 ...
Nate Pet's user avatar
  • 45.2k
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 ...
Álvaro García's user avatar
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
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 ...
Michael Stum's user avatar
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 ...
reggaemahn's user avatar
  • 6,420
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 --&...
Jader Dias's user avatar
  • 89.3k
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 ...
Fit Dev's user avatar
  • 3,513
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!"); ...
George's user avatar
  • 6,699
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
140 votes
14 answers
138k views

What replaces WCF in .Net Core?

I am used to creating a .Net Framework console application and exposing a Add(int x, int y) function via a WCF service from scratch with Class Library (.Net Framework). I then use the console ...
Sigex's user avatar
  • 2,897
134 votes
3 answers
64k views

I'm lost. What happened to ASP.NET MVC 5?

I've been keeping my head down working on various projects and apparently Microsoft has been busy making some big changes and it's confusing the hell out of me. ASP.NET Core first came onto my radar ...
xr280xr's user avatar
  • 12.9k
130 votes
22 answers
154k views

Detected package downgrade warning (dotnet core, vs 2017)

I have just updated all my nuget packages for my solution (dotnet core 1.1 project). I am now getting the following warnings and I don't really know what they mean. Update: I am still getting ...
Nik's user avatar
  • 3,123
130 votes
3 answers
49k views

Are async console applications supported in .NET Core?

At some point in time the CoreCLR supported async main entry points. See http://blog.stephencleary.com/2015/03/async-console-apps-on-net-coreclr.html However both the following programs are not ...
kimsagro's user avatar
  • 16.3k
129 votes
19 answers
173k views

Error NU1605 Detected package downgrade

I am experiencing the following NU1605 dependency errors in my netcoreapp2.0 console application: NU1605 Detected package downgrade: System.Diagnostics.Debug from 4.3.0 to 4.0.11. Reference the ...
Dave New's user avatar
  • 39.3k
127 votes
24 answers
175k views

MSBUILD throws error: The SDK 'Microsoft.NET.Sdk' specified could not be found

I'm trying to build a solution using msbuild command line and I keep getting this error: error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found. The version of msbuild is the latest ...
Luiz Gustavo Maia's user avatar
123 votes
6 answers
51k views

No AppDomains in .NET Core! Why?

Is there a strong reason why Microsoft chose not to support AppDomains in .NET Core? AppDomains are particularly useful when building long running server apps, where we may want to update the ...
Aditya Pasumarthi's user avatar
121 votes
25 answers
154k views

The library hostpolicy.dll was not found

I have a simple .NET Core project (console app) that I'm trying to compile and run. dotnet build succeeds, but I get the following error when I do dotnet run: dotnet run Project RazorPrecompiler (....
Nate Barbettini's user avatar
119 votes
4 answers
139k views

System.ServiceModel not found in .NET Core project

I have a .NET Core xUnit project. I'm trying to call a WCF service from it but get the following exception: System.InvalidOperationException occurred HResult=0x80131509 Message=An error occurred ...
BanksySan's user avatar
  • 28k
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
110 votes
19 answers
178k views

The current .NET SDK does not support targeting .NET Core 2.1. Either target .NET Core 2.0 or lower, or use a .NET SDK that supports .NET Core 2.1

have tried upgrading to the professional version of visual studio 2017 v 15.6.0 (Preview 7.0) and installed aspnetcore-runtime-2.1.0-preview1-final-win-x64 and .net core SDK 2.1.4. When I created a ...
user8559109's user avatar
  • 1,292
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
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 ...
Carlo's user avatar
  • 25.8k
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 ...
Joey's user avatar
  • 1,399
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....
Wilson Silva's user avatar
  • 1,405
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 ...
Alexander Matusiak's user avatar
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: ...
fluter's user avatar
  • 13.5k
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 ...
Krishna.N's user avatar
  • 1,183
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 ...
Christof Jans's user avatar
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 ...
Soheil's user avatar
  • 1,350
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 ...
Robert N. Dean's user avatar
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?
Justin Homes's user avatar
  • 3,769
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 =&...
Ashkan Nourzadeh's user avatar
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 ...
Ali Raza's user avatar
  • 1,051
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 ...
Gigi's user avatar
  • 28.8k
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 ...
Andrei's user avatar
  • 43.5k
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?
ijaz's user avatar
  • 1,150
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 ...
Johannes Heesterman's user avatar
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....
Kemal Tezer Dilsiz's user avatar
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 ...
Justin Helgerson's user avatar
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, ...
James Ko's user avatar
  • 33.4k
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 ...
noshitsherlock's user avatar
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 ...
omar saidi's user avatar
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,...
Miguel Gamboa's user avatar
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....
Levvy's user avatar
  • 1,130

1
2 3 4 5
146