C# Tips
C# Tip

How to use Decimal data type in Entity Framework (EF and EFCore)

9/29/2021
8192 views

In Entity Framework, "decimal" has 0 in its scale by default. For example, if you s...

C# Tip

Unix timestamp conversion built in .NET

8/21/2021
6706 views

In my previous post How to get unix timestamp in C#, I explained how to use unix time...

C# Tip

System.Text.Json - Why does Deserialize() return empty values?

8/7/2021
7228 views

.NET Core 3.0 introduced System.Text.Json namespace which includes some of JSON class...

C# Tip

EF Core 3 Use appsettings.json instead of hardcoded connection string

4/26/2020
8912 views

How do I avoid hardcoded connection string in my DbContext class? using Microsoft....

C# Tip

EF Core 3 Stored Procedure Example

4/26/2020
10292 views

Here is a simple example that shows how to use stored procedure in Entity Framewor...

C# Tip

Ad hoc logging in ASP.NET

4/18/2020
6760 views

I needed to add quick and dirty ad hoc log to staging/test web server. For quick a...

C# Tip

SQL: Select Column When No Row Found

3/6/2020
7666 views

This is not C# topic, but you might be interested since it is pretty tricky case. ...

C# Tip

Using Application-specific Settings

1/10/2020
11432 views

Application Settings allows you to store and retrieve property settings and other inf...

C# Tip

When Control.Invoke() is called before window handle is created

12/12/2019
7735 views

Problem One of my blog readers asked why he was unable to call Control.Invoke() i...

C# Tip

VS 2017 - The current .NET SDK does not support targeting .NET Core 2.1

8/3/2019
6715 views

Problem I downloaded an ASP.NET Core 2.1 project. When I opened the project with ...

C# Tip

VS 2017 - Project file is incomplete. Expected imports are missing

7/28/2019
7075 views

Problem I created new ASP.NET Core 2.1 project in VS 2017. Project build was succ...

C# Tip

How to get the current date and time from internet?

4/30/2019
10231 views

Problem How to get the current date and time from internet? Solution Ther...

C# Tip

How to fix "Could not load assembly System.Data.SQLite.dll"

3/2/2019
6707 views

Problem When I copy a working C# application to another machine, I ran into the fo...

C# Tip

How to download DataTable in Excel format

12/4/2018
6710 views

Problem How to download tabular data such as DataTable data in Excel CSV/TSV form...

C# Tip

How to scroll a panel using mouse wheel

11/24/2018
6756 views

Problem How can we scroll a panel using mouse wheel in WinForms? Solution ...

C# Tip

How to check potential XSS characters

11/8/2018
6763 views

Problem How to check if query string in URL contains potential XSS characters? ...

C# Tip

NumericUpDown control in WPF DataGrid

6/19/2018
7245 views

Problem How to add NumericUpDown control in WPF DataGrid? How to use One ...

C# Tip

VS Server Explorer Error - Login Failed for user

5/24/2018
6700 views

Problem When expanding [Tables] node of SQL Server from [Server Explorer] in Visu...

C# Tip

CLR version vs .NET version

3/8/2018
11019 views

CLR version vs .NET version CLR version and .NET version are different and somet...

C# Tip

Error 0x80004005 when starting ASP.NET .NET Core 2.0 WebApp in IIS

2/3/2018
8782 views

Problem When ASP.NET/.NET Core 2.0 web application is deployed to IIS Server, the ...

C# Tip

Using ref, out param in Lambda

7/5/2017
6712 views

When using Lambda expression, we generally use parameters without specifying their ty...

C# Tip

Entity Framework 6 SQL Server Connection String

6/30/2017
8726 views

1. Entity Framework 6 (EF6) uses LocalDB by default. When EF6 is installed (typi...

C# Tip

VS 2017 error - The command bower install exited with code 9009

4/21/2017
6731 views

Problem Ran into the following error when tried to PUBLISH my ASP.NET Core web pr...

C# Tip

C# error - Cannot initialize a by-reference variable with a value

4/9/2017
8256 views

C# 7.0 introduced "ref return" which allows a method to return "ref" of a value. Som...

C# Tip

How to allow HTML string in MVC

4/7/2017
6724 views

In MVC, how to allow HTML string in POST action?...

C# Tip

Remove ASP.NET server info headers

1/13/2017
8161 views

Some HTTP headers sent by IIS web server disclose server information. And he...

C# Tip

Escape curly brace in string.Format()

12/19/2016
6838 views

Sometimes I make mistakes not escaping curly brace in string formatting. For example,...

C# Tip

How to change default precision and scale for decimal type in EF5

10/18/2016
6947 views

In Entity Frame 5, default precision for decimal property is (18, 2) which means prec...

C# Tip

How to convert GUID to Integer

9/21/2016
38357 views

GUID is 128 bit (16 bytes) data. To convert GUID to integer without data loss, we c...

C# Tip

Error: The "GenerateResource" task failed unexpectedly

8/3/2016
6743 views

When I tried to build a C# project, I ran into the following error. The "Generat...

C# Tip

Pass reference type using "ref"

6/27/2016
7007 views

When a reference type object is passed to another method, one can add "ref" keyword i...

C# Tip

How to restart program in C#

6/10/2016
18293 views

How do you restart the current process in C#? Well basically it is to start the...

C# Tip

Calling SQL Function from C#

6/3/2016
6761 views

A Simple example of calling a SQL function by using ADO.NET. While it is not com...

C# Tip

Tip: equivalent TSQL expression to string.IsNullOrEmpty()

5/23/2016
7526 views

In C#, we can check to see if a string is null or an empty string as follows. if...

C# Tip

Unable to find currently running process when debugging in VS

5/10/2016
6998 views

When running the following code in standalone application, it works fine. stri...

C# Tip

VS : Could not load file or assembly Microsoft.SqlServer.Management.Sdk.Sfc

3/31/2016
8784 views

Sometimes people asked some questions on one of my old blog - "VS 2012 Error : Coul...

C# Tip

foreach creates new iterator for IEnumerable

3/25/2016
6735 views

In C#, foreach statement provides a convenient way of iterating an enumerable object....

C# Tip

VS : Search Solution Explorer

3/18/2016
6735 views

One of great features in Vistual Studio... Search Solution Explorer! On top of S...

C# Tip

How to get process handle from process name in C#

2/22/2016
16724 views

A question from facebook group:How can we get process handle or process id from runni...

C# Tip

C# - Curly Braces in string.Format

2/16/2016
6745 views

I ran into an error when using the following string formatting. // Wrong var s ...

C# Tip

IIS WebSite Debugging Tip

1/22/2016
6865 views

A small note for how to debug a website (ASP.NET) hosted in remote test server. ...

C# Tip

How to check internet connectivity in C#

1/6/2016
8580 views

Since .NET 2.0, there is a method called NetworkInterface.GetIsNetworkAvailable() whi...

C# Tip

How to check the size of HTTP resource

1/5/2016
7146 views

Sometimes we want to know the size of HTTP resource before actually getting it. For e...

C# Tip

Convert long date to short date

12/3/2015
6771 views

How to convert long date string to short date strong? Let's say we got a date stri...

C# Tip

How to prevent flicker in WinForms Control

11/23/2015
15840 views

If you frequently update the content of a WinForms Control, you might observe a flick...

C# Tip

Using TLS 1.2 in C#

11/16/2015
100112 views

.NET 4.0 (or below) supports SSL 3.0 and TLS 1.0 (a successor of SSL 3.0). SSL and TL...

C# Tip

Primitive types in C#

10/28/2015
7194 views

In CLR, the primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, I...

C# Tip

C# Multi-dimensional Array Size

10/23/2015
6759 views

When it comes to multi-dimensional array, C# supports two kinds of multi-dimensional ...

C# Tip

How to empty Recycle Bin in C#?

10/21/2015
6753 views

.NET Framework does not have handy way of emptying the Recycle Bin files. But this ta...

C# Tip

.NET Framework source code online

10/14/2015
7068 views

Someone in Facebook asked a question, 'where can I find .NET Framework source cod...

C# Tip

C# Union

10/7/2015
6740 views

In C/C++, union is a user-defined type in which all members share the same memory, bu...

C# Tip

EF Code First: How to insert master/details data

10/1/2015
15625 views

I have Order and OrderDetails table which has one to many relationship. How do I ...

C# Tip

C#: The pitfall of equality operator

9/28/2015
6724 views

I ran into equality operator (==) issue again. That is, when equality operator compar...

C# Tip

Understanding DB NULL in C#

9/23/2015
6690 views

It is not unusual for C# developer to mix DBNull up with pure "null." Tak...

C# Tip

Using Identity column in EF7 (VS 2015 ASP.NET 5)

9/21/2015
6748 views

Visual Studio 2015 (RTM) provides ASP.NET 5 Preview Template and this project templat...

C# Tip

Turkish i in C#

9/11/2015
9425 views

When comparing parameter with literal value, it is common to make it to uppercase or ...

C# Tip

Uppercase, Lowercase, Title case in C#

9/8/2015
6693 views

.NET String class has ToUpper() method which changes all characters to uppercase and ...

C# Tip

How to ping in C#

8/31/2015
6973 views

Ping is typically used to check a computer's availablity. Ping uses ICMP echo req...

C# Tip

How to change system time in C#?

8/25/2015
20566 views

In C#, DateTime struct does not have any method to set system time. How can we change...

C# Tip

C# round up issue in Math.Round()

8/24/2015
10361 views

To round up a number, C# uses a .NET method called Math.Round(). For example, Math.Ro...

C# Tip

How to wipe a file completely

8/21/2015
6766 views

We might want to wipe a file completely so that the file can never be recovered. Som...

C# Tip

How to fade in (or fade out) my form

8/18/2015
6709 views

How can I fade in and/or fade out my form (WinForms)?...

C# Tip

How to display custom string for enum value

8/5/2015
6753 views

How can we show user-defined string for enum value? For example, want to display &quo...

C# Tip

When not to use nvarchar(max)

8/3/2015
6962 views

Entity Framework has an annotation (StringLength) to set max length of string field. ...

C# Tip

C# : How to launch browser and visit web site?

8/2/2015
14514 views

In C# desktop application, how can we launch browser and navigate to a specifc web si...

C# Tip

Bug Fix: Invalid viewstate / Unable to find assembly

7/27/2015
6713 views

Bug Fix: Invalid viewstate / Unable to find assembly An exception was thrown fr...

C# Tip

When int? value is null

7/22/2015
6746 views

An interesting question: is it possible to access property or method when int? value ...

C# Tip

Bug Fix : Cannot close stream until all bytes are written

7/21/2015
18255 views

This is about a bug that I found recently. One component calling other company&#...

C# Tip

Convert byte array to hex string

7/17/2015
7583 views

Sometimes we need to convert byte array to a concatenated hex string. Nice thing abou...

C# Tip

How to get unix timestamp in C#

7/13/2015
6806 views

The unix time stamp is the number of seconds between a particular date and the Unix E...

C# Tip

How to hide form when button is clicked

7/7/2015
6755 views

I want to capture the entire screen from my winform application. I have a button ...

C# Tip

Finding element index of a list using LINQ

7/6/2015
6816 views

One interesting way of finding an element index of a list using LINQ. Enumerable...

C# Tip

Ambiguous method overloading - string vs string[] args

7/1/2015
6788 views

A question from a Facebook C# group. How can we get around the ambiguous method o...

C# Tip

Integer division to get decimal result

6/28/2015
6779 views

Sometimes Web API can return money data as an integer. For example, Stripe API (f...