Click here to Skip to main content
15,890,399 members
Everything / Programming Languages / C# 6.0

C# 6.0

C#6.0

Great Reads

by Qwertie
It has 41 features in about 1000 lines of code* - but only 3 lines are needed to parse the expressions you type in. Uses WinForms, BackgroundWorker, GDI+ and LES.
by Ratish Philip
The next version of the useful WPF controls is here
by phil.o
This article describes the building of Markov Chains and their use for generating random names or words.
by Kenneth Haugland
How to connect hot observables to Rx

Latest Articles

by Dave Elliott
A series of 6 articles to provide you with a boilerplate guide to create Source Generators.
by Dave Elliott
A series of 6 articles to provide you with a boilerplate guide to create Source Generators.
by Dave Elliott
A series of 6 articles to provide you with a boilerplate guide to create Source Generators.
by Dave Elliott
A series of 6 articles to provide you with a boilerplate guide to create Source Generators.

All Articles

Sort by Updated

C# 6.0 

N 23 Apr 2024 by OriginalGriff
Name in C# - variables, methods, properties, namespaces, everything which can be named - are precise: they have to match exactly. That means underscores, the case, and the letters must be identical for two names to "match". For example, "Count"...
N 23 Apr 2024 by s yu
I am revising a solution w/ multiple projects. I added a new project (or namespace), named as _NewProj. In an existing .cs, I added using _NewProj However, I received IDE0005 error: Using directive is unnecessary. How to resolve it? Thanks. ...
20 Feb 2024 by Maciej Los
I'm no sure what you want to achieve... I believe below example will help you to understand how to filter your data. DECLARE @cn AS INT = 253; -- 253 --594 --2132 DECLARE @ip AS INT = 1; DECLARE @pcn AS INT = 0; WITH cte AS ( SELECT...
19 Feb 2024 by DT_2
I need to find the immediate parent id based on the below condition: |CustomerNum|ParentCustomerNum|IsPlatform| |-----------|-----------------|----------| |132 |0 |1 | |253 |132 |0 |...
18 Jan 2024 by Dave Elliott
A series of 6 articles to provide you with a boilerplate guide to create Source Generators.
18 Jan 2024 by Dave Elliott
A series of 6 articles to provide you with a boilerplate guide to create Source Generators.
18 Jan 2024 by Dave Elliott
A series of 6 articles to provide you with a boilerplate guide to create Source Generators.
18 Jan 2024 by Dave Elliott
A series of 6 articles to provide you with a boilerplate guide to create Source Generators.
18 Jan 2024 by Dave Elliott
A series of 6 articles to provide you with a boilerplate guide to create Source Generators
18 Jan 2024 by Dave Elliott
A series of 6 articles to provide you with a boilerplate guide to create Source Generators.
20 Nov 2023 by Richard Deeming
You have no [Authorize] attribute on your ValuesController or any of its actions. Unless you have some configuration that you haven't shown, all of those actions will allow anonymous callers. Simple authorization in ASP.NET Core | Microsoft Learn[^]
20 Nov 2023 by Andre Oosthuizen
Ok, so first - to run some error checking outside of your app, clear your browser cache or any other caching mechanisms that might be storing the old token as this might become an issue. I have converted your code to what I think might work,...
20 Nov 2023 by A Belal
I get tokenKey from path https://localhost:7107/api/login And when i try to test token and get data from Path https://localhost:7107/api/Values the token work good and data comes well but when i remove token the data continue come and...
5 Nov 2023 by Evilfish2000
This has bugged me for DAYS, but I think I found the cause of the issue. I am creating a windows service, that can load different projects and execute them. These smaller services can do various tasks. This works very well. However, I started a...
19 Oct 2023 by Rajesh Kumar 2013
I need to download an Excel file named "Book1.xlsx" from wwwroot folder when I click a Download button. Download I have tried the below code. But it is...
19 Oct 2023 by M Imran Ansari
I'm assuming, you are working with ASP.NET Core application, to download a file from the wwwroot folder when a button is clicked, you can use the PhysicalFile method and return a FileContentResult from the controller. Here's an example: using...
5 Oct 2023 by Rajesh Kumar 2013
I am working with .NET Core 6. There, on button click event, after inserting data, I want to show message that data is inserted successfully. But Response.Write is not supported in my class EmployeeService.cs. How do I use Response.Write? Here...
5 Oct 2023 by Richard Deeming
Clearly your class doesn't have a Response property. But without seeing what your class is doing, and how it's being used, we can't really tell you how to "fix" it. Personally, I'd be inclined to change the class so that it knows nothing about...
13 Jul 2023 by Member 12702056
What is the difference between char zero and normal zero in c++? especially i mean in c++for example,char x=0;int x=0;and char x='0'or just like '0'what is the difference between all of them?what is the exact meaning of them?Please,help me :)What I have tried:I know that...
5 Jul 2023 by Graeme_Grant
Gpoogle search has many examples of how to do this simple task: asp.net core hidden field - Google Search[^]. Here is the first search result: Using Hidden fields in ASP.NET CORE - Tutexchange[^] From their example:
5 Jul 2023 by ahmed_sa
I work on asp.net razor page .i face issue when navigate to page after make submit it reset all values on page I read more the issue will solved by using hidden fields so suppose I have asp.net razor page have username and email and i need...
6 May 2023 by OriginalGriff
This is one of the most common problems we get asked, and it's also the one we are least equipped to answer, but you are most equipped to answer yourself. Let me just explain what the error means: You have tried to use a variable, property, or a...
6 May 2023 by ahmed_sa
I working on MVC razor pages asp.net core 7 . I can't display success message after submit and insert data on same page . I get error System.NullReferenceException: 'Object reference not set to an instance of an object.' error happen on...
4 May 2023 by Kondrolla Ruchitha
HI, When i'm trying upgrade my unittest project i'm getting error failed to convert to SDK style. in .net6.0. How can we solve this issue? Is there any way to upgrade unittest project from framework to .net6.0? Thanks What I have tried: ...
24 Apr 2023 by Richard Deeming
Quote: Unrecognized configuration section system.web. The problem is that you have a section in your app config file. That section was used to configure ASP.NET in .NET Framework. It does not apply to .NET 6 applications, nor to...
24 Apr 2023 by C Pottinger
I have been having this issue for some time now. When I start my console app, log4net keeps throwing the same error several times. I have tried numerous ways to get around the issue but it always occurs. The code: public class Announcer ...
6 Mar 2023 by ahmed_sa
I working on blazor server . i get error evaluation function required all threads to run i get this error when login on var resultIdentity = await signInManager.PasswordSignInAsync(UserName, "xxxxx", false, false) it stop on this line and...
6 Mar 2023 by Richard Deeming
That is not an error; that is a message from the debugger telling you that you cannot inspect a particular variable unless you allow all threads to run. There will be a small icon that looks like twisted threads next to the message or the...
6 Mar 2023 by ahmed_sa
I work on asp.net web forms . I face issue I can't display previous and next button with Numeric page number . current status display page number numeric mode only as 1,2,3,4 etc. but I can't display previous and next with page numbers so How...
5 Mar 2023 by itsathere
// Online C# Editor for free // Write, Edit and Run your C# code using C# Online Compiler using System; using System.Globalization; public class HelloWorld { public static void Main(string[] args) { string...
5 Mar 2023 by OriginalGriff
If I copy and paste your code into an online compiler (C# Online Compiler | .NET Fiddle[^]) and type in todays date it works fine: using System; using System.Globalization; public class Program { public static void Main() {...
13 Feb 2023 by Andre Oosthuizen
As per your link, a reference to ensuring the path is correct to your ADFS server - The path to the ADFS XML metadata is always your ADFS server FQDN, followed by a path to the FederationMetadata XML document To solve your problem, check...
13 Feb 2023 by $ultaNn
Dear i ave followed steps given in this Link when I debug the application, I am getting Error This site can’t be reached What I have tried:
4 Feb 2023 by ahmed_sa
I work on c# console application I need to add data table rows to list using c# so How to do that please ? so How to add rows from data table to object list ? meaning How to store row[0].ToString() on list . What I have tried: string...
4 Feb 2023 by Graeme_Grant
Why not something like: string connString = @"your connection string here"; string query = "select * from table"; SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = new SqlCommand(query, conn); conn.Open(); // create a data...
26 Jan 2023 by Member 15639943
Hello everyone, I'm working with VS2022, C# WPF and I want some reports using RDLC, I have already downloaded Microsoft RDLC designer 2022. I have already made the first design of the report. But in my XAML window when trying to use ReportViewer ...
26 Jan 2023 by Member 15639943
I uninstalled and reinstalled RDLC for 2022 and it seems to have fixed the problem.
25 Jan 2023 by Member 15639943
I've found that the problem is here in the XAML code: xmlns:rv="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms" I have instaled Microsoft RDLC Report Designer 2022 without problem, but the files...
24 Jan 2023 by Andre Oosthuizen
It seems that the newest feature of RDCL has been released in the VS Marketplace since vs2022 v17.1 as per MICROSOFT. You can either go to THIS link to download the vsix file or you can do the following - 1. Open VS2022 2. In your top menus, go...
24 Jan 2023 by gsteinberg@satoriassured.com
I apologise upfront as I am new to Dev and researching this for a solution. This might not even be a big problem and a common issue. We have a multi-tenant database that has a tables by customer but dynamic columns. Customer A may have 4...
22 Dec 2022 by AmitRHadge
I have PKCS12 file (secured by password) which contains Aux key and main key generated using aux key. Now I am trying to read the keys programmatically in C#. Please let me know am I missing something? or the approach I am following is not...
6 Dec 2022 by Bal krishna sharma
[HttpGet("getDeparts")] public async Task> getDeparts(string DeptName) { User ues = await DBCon.department.Select( s => new User() { id=s.id, ...
1 Dec 2022 by User-8621695
Hi Experts, I've created around 10 MVC projects (different solutions) for a single web application. I did it too keep code simple and separated. Now I am trying to run these as a single web application. Like from Login->Menu->Student. Please...
1 Dec 2022 by Richard Deeming
You can use class libraries for models, controllers, services, and views. It's fairly trivial to do in ASP.NET Core: Share controllers, views, Razor Pages and more with Application Parts in ASP.NET Core | Microsoft Learn[^] In MVC5, it's...
28 Nov 2022 by Bal krishna sharma
using SingerAPI_6.Entities; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using MySqlX.XDevAPI; using System.Collections.Generic; using System.Net; using System.Threading.Tasks; using System.Linq; using...
25 Nov 2022 by ahmed_sa
I work on .csharp net core 5 i need to create blazer app with good architecture with clean code are any one know GitHub link source code for that or any sample on internet site i can follow it . What I have tried: sample for blazor good...
25 Nov 2022 by OriginalGriff
To add to what Dave has said, no single example of "clean code with good architecture" applies universally for all projects, even within a single framework like Blazor! What works well for one app would be a disaster for others, and vice versa....
25 Nov 2022 by Dave Kreskowiak
I'm sorry to tell you that just looking at examples is not going to teach you how to write "clean code with good architecture." What you want is a result of proper software design philosophy, which you're not going to learn from looking at some...
10 Nov 2022 by Bal krishna sharma
Unable to resolve service for type 'BasicAuth.Entity.DBContext' while attempting to activate 'BasicAuth.Controllers.EmployController'. at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type,...
10 Nov 2022 by Graeme_Grant
Here is a walk-through on getting it to work: Using Authorization with Swagger in ASP.NET Core - Code Maze[^] Dot Net 7.0 (just released) makes it even easier: Making the Most of Minimal APIs in .NET 7 | .NET Conf 2022 - YouTube[^] - I have...
9 Nov 2022 by Richard Deeming
Nowhere in your ConfigureServices method have you registered the BasicAuth.Entity.DBContext type. That would usually be registered via an AddDbContext[^] or AddDbContextPool[^] call. If you don't register the services in the DI container, then...
2 Nov 2022 by RickZeeland
Maybe you can find an example here: Search CodeProject PGP[^] This might be the solution to your problem: PGP Decryption - Unnecessary exception stops execution · Issue #143 · bcgit/bc-csharp · GitHub[^]
1 Nov 2022 by runtime_terror
Hi, I am trying to encrypt a file using a public key (e.g. abc_public.asc) generated through PGPTool, which was shared with the client. The client shared a private key (xyz.asc) in return, in which the PGPTool shows as 'Public' (xyz.asc) and 'Key...
26 Oct 2022 by Ahmed Salah Oct2022
namespace program { class program { static void Main(string[] args) { int[] grade = new int[10]; int[] cre = new int[10]; string[] gpa = new string[10]; double[] gs = new...
26 Oct 2022 by George Swan
What I would suggest is to use generic lists rather than arrays as the list size is not a fixed value so you avoid the empty array cell value problem. Rather than have multiple if then else statements in your code you can calculate the results...
25 Oct 2022 by Graeme_Grant
You need to add a test statement in your second loop... for (int i = 0; i
24 Oct 2022 by GuinnessNH
Add this line beforehand (use the Commercial enum if Commercial). ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
24 Oct 2022 by Member 14061262
I am using below code to read SharePoint excel file using EPPLUS var webRequest = HttpWebRequest.Create("SharepointURLPath") as HttpWebRequest; webRequest.UserAgent = @"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)...
23 Oct 2022 by AyGok
Hi, I get the process ids of the applications or windows opened via windows service and log them, but I noticed that, for example, the tabs opened in chrome always give the same PID, and at the same time, it always gives the pid of...
23 Oct 2022 by CHill60
In previous versions of IE you could change a registry setting, but it was unreliable. For IE11, have a look at the solution here - https://superuser.com/questions/1130849/internet-explorer-11-process-per-tab[^] You should also take note of...
19 Oct 2022 by Member 15803157
I Have A desktop Application with c# I Created An API Called GetAsync it Get's me Some Data From Remote Server (Table Name Is TempData) what I want to do Is To Get My Data Inside New List Of TempData To Preview It Inside Datagridview public...
19 Oct 2022 by Ahmed Elbaz
Just change the return type to List as follows: public static async Task> GetTempData()
10 Oct 2022 by syed shanu
Blazor Server APP in ASP.NET Core 6.0
6 Oct 2022 by runtime_terror
Hi All, I need a solution for converting a simple PDF to PDF A/3 format with xml file embedded by adding an image or icon before converting to a/3 format with any open source. Please help Thanks in advance What I have tried: byte[]...
2 Oct 2022 by RickZeeland
Take a look at this CodeProject PDF library: PDF File Writer C# Class Library (Version 2.0.0)[^]
17 Sep 2022 by ahmed_sa
I work on .net windows form applications on visual studio 2019 i need to make windows form pos point of sales to pharmacy so whaich is best tools for that using normal datagridview or devexpress gridview also if there are any sample code on...
16 Sep 2022 by TCS54321
i have a json file and json data is something like that:- { "Partdetails ": [ { "key": "pincode", "value": "34598702" }, { "key": "deliveryStatus", "value": "OptedOut" }, { "key":...
16 Sep 2022 by Graeme_Grant
You need to write a custom converter to handle this: How to write custom converters for JSON serialization - .NET | Microsoft Learn[^]. I have also written an article on writing custom converters: Working with System.Text.Json in C#[^] Here is...
16 Sep 2022 by Richard MacCutchan
You need to use the proper context for deserialization: https://docs.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializer?view=net-6.0[^].
16 Sep 2022 by TCS54321
i need to create an api in which final output would be look like that:- { "authdata": { "version": "1.0", "Type": "APIResponse", "PDateTime": "9/14/2022 6:18:34 AM", "status": "SUCCESS" }, "data": [ { "orderID": "",...
16 Sep 2022 by Richard MacCutchan
You are trying to create data as a List, not as an orderdata item: data = new List { orderID = oid, Orderdetails = odData Partdetails = pdData } And Lists do not contain members named orderID, Orderdetails or Partdetails.
14 Sep 2022 by Siddharth Rai
Hi, I am not able to make clear understanding Issuer and audience role in JWT token authentication please help to make better understanding. currently i am passing the Issuer and Audience both same because as localhost i am generating the token...
11 Sep 2022 by lalit.mca2006
Hi, I have a date column in sql server which shows date as '2022-09-11 10:12:48.830' i have to find whether date is older than 24 hours in C# dotnet core. I tried below code , but it gives error- formatexception: string '2022-18-11...
11 Sep 2022 by OriginalGriff
Don't convert dates to strings in order to convert them: convert strings to DateTime and compare those. Equally, if it's a DATETIME, DATETIME2 or DATE column in SQL, then it automatically converts to a DateTime in C# (as it's stored in both as a...
10 Sep 2022 by lalit.mca2006
Hi, I am using below code to upload file(IformFile) using swagger. I came to know that in new framework we must implement IOperationFilter . Here is my code: using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; ...
5 Sep 2022 by Sunil Murarka 2022
I am implementing but text editor now showing on text area, I follow all steps mentioned on tinymce doc. What I have tried: I am very much thank full, please give complete guid
5 Sep 2022 by OriginalGriff
Go back to where you got the text editor source from, and ask there: we don't have any idea what package you are using, or how you are using it, much less how you were supposed to use it! They at least will know their product much better that we...
18 Aug 2022 by Know Everything
In the link below you will find a binary data file which contains a position for each of 2 million vehicles. Your task is to write a program that can find the nearest vehicle position in the data file to each of the 10 co-ordinates provided...
18 Aug 2022 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
14 Aug 2022 by ahmed_sa
I work on csharp i get error object reference not set to an instance of an object code give me error ElasticPartialUpdat.Create.error.get returned null. so how to solve error please ? What I have tried: var Data = result.items.Select(e =>...
14 Aug 2022 by OriginalGriff
This is one of the most common problems we get asked, and it's also the one we are least equipped to answer, but you are most equipped to answer yourself. Let me just explain what the error means: You have tried to use a variable, property, or a...
9 Jul 2022 by Member 8583441
I am designing an api for Educational field. So, I have created WebAPI with authentication mode windows in .Net6. I am having two controllers namely, AuthController and TeacherController. AuthController for authorizing the user and to create JWT...
1 Jul 2022 by Member 10738936
This issue comes on live server. In local IIS its working. for deserialize i am uing var data = JsonConvert.DeserializeObject(response.Content); this is my json: {"Table":[{"OrganisationID":1001,"NAME":"LORD MEHER INTER...
30 Jun 2022 by ahmed_sa
I work on asp.net core 3.1 web api I get exception error as below : Exception The target file is a directory, not a file. on file.copy this lines generated exception System.IO.File.Copy(OutputfilePath, Path.Combine(exportDirectory,...
30 Jun 2022 by Member 15560489
I know this is an old topic, but maybe it will save some time to someone. I was just having the same problem. Turns out I was calling Directory.CreateDirectory(path); where path had the file name in it. But this actually creates a folder with a...
20 Jun 2022 by Robert Donnan
Yes, following the past comments. I was having the same MSB3026 issue appear and tried changing the file permissions etc, nothing worked. Then I deleted the obj file and the bin file but it didn't work due to the file being opened elsewhere....
20 Jun 2022 by Wolfgang Kurz
Hello, when I try to debugg my C# .NET application it sometimes happens that VS Community 2022 cannot store the result (WPF_CFG.exe file) of a new compilation. WPF_CFG is the project name, it stands for ...
13 Jun 2022 by Graeme_Grant
I loaded up a project and ran your code modified and works as expected. Here is the code that I used: 1. Flange Class (changed fields to properties) public class Flange { public string Name { get; set; } public string Description { get;...
13 Jun 2022 by Member 12687352
Hi there. I'm using Visual Studio 2022. I have an error prompt that I had no experience with. the program has a class named Common as follows: namespace WindowsFormsApp1 { public class Common { public class flanges { ...
10 Jun 2022 by OriginalGriff
C# is case sensitive: Common is not the same as common. So this: public class Common { public class flanges { .... } Does not match with this: private List _Flange=new List(); It's also...
10 Jun 2022 by #realJSOP
If you insist on wanting to "change the property name (which I personally think is a TERRIBLE idea), just create a couple of getter/setter extension method that does what you want: public static int MyRenamedProperty(this MyObject obj) { ...
23 May 2022 by TheBigBearNow
I been having some major issues with this, I feel like this shouldn’t be so hard but.. I am trying to be able to open a link which brings pictures to the browser to display them. I have this working. What I am trying to do is when someone opens...
10 May 2022 by Dave Kreskowiak
If your site is dependent on those databases, you have no choice but to connect via the VPN to get at them. This is question more for your company IT about your VPN issues than anyone else.
10 May 2022 by Member 14806991
Hello, in my current job, we have all the databases on the company network and I connect to the company network through Cisco anywhere connect but my problem is the VPN connection is not stable and usually disconnects. I have a deadline coming...
5 May 2022 by Shazma Batool
I am a newbie. I have read in many blogs that const keyword can only be used with primitive types in C# but why? What is the reason behind this limitation? What I have tried: I have searched this query in Google but haven't find any reasonable...
5 May 2022 by OriginalGriff
As Dave says, const values are constants, and only primitive types can be expressed as a constant literal at compile time. However, there is readonly which is the struct / class equivelant - a value that can only be set in an instance constructor...
5 May 2022 by Dave Kreskowiak
Because const are not variables. Even though they are named, they are really just a compile-time replacement of a value wherever it's used. Reference types specified as const can only be null. They cannot have an instance. An instance cannot be...
23 Apr 2022 by ahmed_sa
i work on csharp issue but i don't know how to solve it i have two classes A AND B how to instaniate it as below A a =new A(); A B =new B(); What I have tried: i don't know how to make it can you help me
23 Apr 2022 by OriginalGriff
A a = new A(); A B = new B(); If that code is correct, then class B has to be derived from (or inherit) class A: public class A {...} Public class B : A {...} Then, a variable containing an instance of A can also contain an instance of B because...
21 Apr 2022 by Richard Deeming
Simple: ^[-+]?\d+(\.\d+)?$ .NET Regular Expressions | Microsoft Docs[^] But depending on your requirements, it would probably be simpler to use decimal.TryParse to test whether the string is a valid number. Edit: Excluding zero is slightly...