Monday, December 22, 2014

Thursday, December 18, 2014

How to solve problem "Cannot find the requested object." while create an X509Certificate2 object?


It throws this exception for following line:
X509Certificate2 certificate = new X509Certificate2(@"c:\temp\server.pvk", "password");

It means: the certificate file is not valid.
The most common reason is:
Need pvkimprt tool to generate PFX files

Reference:
http://msdn.microsoft.com/en-us/library/ms148420(v=vs.110).aspx
This constructor creates a new X509Certificate2 object using a certificate file name and a password needed to access the certificate. It is used with PKCS12 (PFX) files that contain the certificate's private key. Calling this constructor with the correct password decrypts the private key and saves it to a key container.

Following are the steps to generate X509Certificate2

"C:\Program Files (x86)\Windows Kits\8.1\bin\x64\makecert" -r -pe -n "CN=Test" -sky exchange c:\temp\server.cer -sv c:\temp\server.pvk -sr currentuser
"C:\Program Files (x86)\Windows Kits\8.1\bin\x64\cert2spc"  c:\temp\server.cer server.spc
pvkimprt -pfx server.spc server.pfx

Tuesday, December 16, 2014

In MS SQL, how to count total number of major objectsr, such as table, view, store procedure etc?

Select type_desc as Type, COUNT(*) AS Count from SYS.OBJECTS
Where type_desc not in ('SYSTEM_TABLE','INTERNAL_TABLE','SERVICE_QUEUE')
group by type_desc

The Art of Programming


https://medium.com/@erikaheidi/the-creative-programmer-2dde54f83e3a

Thursday, December 11, 2014

What is the simplest way to solve "Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on"

Code Example

Replace
list.Items.Add(status);
with:
                    this.Invoke((MethodInvoker)delegate
                    {
                        //list.Items.Add(status);
                    });


C# Naming Conventions with example

use PascalCasing for class names and method names.
use camelCasing for method arguments and local variables
use noun or noun phrases to name a class.
prefix interfaces with the letter I.  Interface names are noun (phrases) or adjectives.

References:
http://msdn.microsoft.com/en-us/library/ms229043.aspx
http://www.dofactory.com/reference/csharp-coding-standards

Wednesday, December 10, 2014

How to list all of listening ports in Windows command prompt?

netstat -anb | findstr /R /C:"[LISTENING]"

How to solve problem "No connection could be made because the target machine actively refused it"

#1 reason is: target machine TCP not listening.
Can run following command line to check:
netstat -anb

What is difference between 0.0.0.0 and 127.0.0.1?

127.0.0.1 is localhost. Only same machine can access this address.
But 0.0.0.0 means all of ip addresses binding to this machine.

Reference:
http://blog.lauramamina.com/article?title=0.0.0.0%20vs%20127.0.0.1

Workflows of Refactoring

http://www.infoq.com/presentations/workflow-refactoring





Uri Templates

https://github.com/tavis-software/Tavis.UriTemplates

Usage:
        var url = new UriTemplate("http://example.org/{tenant}/customers")
            .AddParameter("tenant", "acmé")
            .Resolve();

        Assert.Equal("http://example.org/acm%C3%A9/customers", url);

Monday, December 8, 2014

5 Incredible Features in the Visual Studio 2015 Preview


http://developer.telerik.com/featured/5-incredible-features-visual-studio-2015-preview

Friday, December 5, 2014

How to solve Invalid Xml syntax error after updated an older Visual Studio project



Error message:
This application has failed to start because the application configuration is incorrect. Review the manifest file for possible errors.
Reinstalling the application may fix this problem. For more details, please see the application event log.

In EventView, the error message is:
Activation context generation failed for XXXXX
XXXX on line 1. Invalid Xml syntax.

The first line in config file is
<?xml version="1.0" encoding="Windows-1252"?>

Solution:
Change to
<?xml version="1.0" encoding="utf-8"?>

Wednesday, December 3, 2014

Free browser base UML modelling tool

https://www.draw.io/

How many kind of UML diagrams in total?


Class Diagram
Component Diagram
Deployment Diagram
Object Diagram
Package Diagram
Profile Diagram
Composite Structure Diagram
Use Case Diagram
Activity Diagram
State Machine Diagram
Sequence Diagram
Communication Diagram
Interaction Overview Diagram
Timing Diagram


http://creately.com/blog/diagrams/uml-diagram-types-examples



Tuesday, December 2, 2014

How to install SQL Server management studio only?

On the download page:
http://www.microsoft.com/en-us/download/details.aspx?id=29062

Select the file just for SQL Server management studio installation:
ENU\x64\SQLManagementStudio_x64_ENU.exe

How to get list of SQL Server instances on local machine?

In command line prompt (Run as admin):
reg query "HKLM\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL"