32 minutes to read read

Recently started with TypeScript with Visual Studio for the AngularJs and landed into a deep problem. The problem was that i was on a blank solution/project with no changes, and still there was a build error. The transition was assumed to be ok, but it didn’t turned out. So here  are the steps I did:

  1. Create a new MVC project in Visual Studio 2015. Added references for Angular using the PM Console.
    Command: install-package angularjs
  2. At this point solution should compile well.
  3. Install the DefinitrlyTyped typings for TypeScript for angularjs from PM Console.
    Command: install-package angularjs.typescript.definitelytyped
  4. Once installed, the solution should still compile ok, because as of now there is no TS file in the solution that should be compiled.
  5. Add a .ts file to the project and add a simple function. This would initiate the TSC to come in picture and compile ts bindings.
  6. Now building the solution gives a whole lot of compiler errors and compiler fails. The main errors are TS2304, TS2411, TS2320, . I get around 482 of such errors. The error loig from visual studio is attached below:Continue reading

5 minutes to read read

The Problem

Managing the configuration data have always been troublsome. Although Microsoft did provided and also updated/upgraded a lot of options from time to time, yet it remains  a challenge most of time. Things get more critical when the configuration data we are concerned is the confidential data like connection string, smtp passwords, API keys etc becase at some point of time, they do get checked in source code or shared across other developers. In one of my prev project faced a similar issue when private key and the Code Signing certificate was accidentally checked in by a developer. The customer had to revoke the certificate which invalidated all the production builds which were deployed to end users as well.

The Solution: ConfigurationBuilder()

With ASP.net there are some pretty cool enhancements that Microsoft added especially with the Configuration Builder. Earlier whole of .net relied on System.Configuration Namespace to get the configuration data. With the current version it has been greatly re-architeced which now provides a simple key value pair from multiple sources prebuild or even custom providers (like azure or mongoDb) which we shall try out in next post.

Continue reading

6 minutes to read read

By the end of First project we already have a WebApi Self Hosted in Windows Service, but on HTTP. In this post i shall try to add a SSL layer over the top if it to provide additional transport layer security. Things are much easier with IIS, which provides default and simple settings and configurations for all settings like SSL or others.But moving things out of there can be a little tricky. Also, in this post, we shall not be using the developer certificate generated by the IIS, but an actual one issue by CA. For this we shall first register an CA Certificate and then SSL. So let’s roll.

The Tools

We shall be using the following tools provided by Microsoft that can be accessed from developer command line tools.

  • makecert
  • pvk2pfx
  • netsh (provided by windows)

PS: If you can get a proper SSL Certificate from a commercial CA, you can directly move here.

Creating the CA

All the certificates are issue by Certifying Authority or a CA. So for creating an CA, fire up the “Visual Studio Command Line Tools” and run as administrator. I would recommend create a new folder and browse to that so that things dont mix up.

Type in the following command to generate a new CA certificate.

Continue reading

4 minutes to read read

With the introduction of OWIN  and self hosting, microsoft has really opened a lot of possible doors for developers and application users. This post is targetted to have an OWIN application hosted in Windows Service. Also we would be configuring the SSL for the Site.

Source code can be accessed at: GitHub

Creating a Windows Services Project

This is pretty straightforward. In visual Studio, Create new project and select Windows Service as project. This will add a project with default Service “Service1”. Rename to whatever the name expected.

Add OwinSelfHost and WebApi2

In the Tools-> Nuget package Manager -> PM console type in the following command to get the WebApi and self host packages referenced.

This will install and reference all the required packages and dependencies. Also we need one more package to debug and use some functions like welcome package. For this import the  Microsoft.Owin.Diagnostics using PM Console.

Also, to Enable Cross Origing Resource Sharing, we need to import the following package:

At this point the we are Good to Start.

Continue reading

3 minutes to read read

NLog Targets

The beauty of NLog is the Targets ‘system’ that is extentible and easy to use. Also the most amazing thing is the default target list as provided by NLog and the ease with which custom targets can be written. The Targets provided by the Nlog  by default are more then sufficient for most needs.

There can be multiple targets that can be linked to multiple Rules.

Well, the currently provided targets as provided by NLog can be accessed here. Some of the most useful targets with sample configuration is as below:

  1. ColoredConsole: This target adds a ‘beautiful’ Colored logs on the console. Well from the name it applies for Console Applications only.
  2. File Target: The file target as form the names writes the log to any file. Also, the location of the file could be on the network path as well.

    There are two targets as defined above, one is normal file in local system and the other one is on network path. The archival options availabel for Files can be seen here
    There is also an possiblity to add more advanced options to control file parameters. An example code is given below as:
  3. Debug Target: As the name suggests it writes to the Log sink for the attached debugger  (if any :))
  4. Trace Target:  This also as prev, send the messages to system.Diagnoistics.Trace Listener. This can be useful, if there are any existing trace listeners, and nlog is to be configured to integrate with them.

Continue reading

2 minutes to read read

There are a plenty of logging tools and options in todays market but the userful are some. Almost all of them if not some do work on similar baseline, a set of rules to route and a sink to put in the logs. Some are really cool but have lost their sharpness with the low or no community updates like log4net which had been a great library for logging almost anything with .net. Some other good stuff like in the “Microsoft.Practices” namespace are also good but do have a good learning curve.

At this point NLog comes out as a wonderful logger with lowest learning curve, fastest adaption, small footprint, async support, and a large set of targets that can fulfill almost all requirement. With these set of articles, I shall try to put how easy it is to employe the hardlifting of logging in your projects. For this post, we shall take out lovely Simple Console Application. The download link for sample code can be found at the end of the post. Also note we are not using any abstract or patterns, this is just to demonstrate a brief purpose.

So, We first created the the Default Console Application Project with all default settings. And the we did a nuget install for nlog. This shall install the latest version of the package to project.

Once we have this, we are pretty good to start. Second Step Continue reading

< 1 minute to read

Just another day with Windows 10 and got restoring my TFS Server. This has been a very common error and perhaps the first thing you see when you browse to your tfs page after restoring the database.

Critcal error: TF30046: The instance information does not match. Team Foundation expected 50623DA5-2C61-42F3-B57B-D1145C16B187 which was not found. Please contact your Team Foundation Server administrator.

The reason for this is very simple. Each TFS installation has an installation instance ID that is mapped to vertual application id setup. So what is happening here is that the Virtual Web application is looking for a new TFS instance Id which is basically a GUID. But we have restored older database. So perhaps we have the following option as sure and simple solution.

  1. Open Database instance in Sql Server Management Studio and open database TFS_Configuration
  2. Go to tbl_ServiceHost table and look for entry where Name  = “TEAM FOUNDATION”. Copy the HostId
  3. Go to TFS INSTALL FOLDER \Application Tier\Web Services folder
  4. Open the web.config and update the value for applicationId  key with the value copied in step 2
  5. Restart the IIS for application tier virtual application
  6. You are good to go…