Jul 242017

I wanted to create a self hosting console application without going to the hassle  of creating a new web application project. So all i had to do was to create a console application and then do the nuget and OWIN do the rest.

Create a new console project and paste this code in the main procedure.


So the first thing that you will see if that you will get error as it is unable to identify the WebApp class. So the first thing that you need to do is to include the nuget package. Include the nuget package called ‘Microsoft.AspNet.WebApi.OwinSelfHost’ to the project and then try to compile and run the project. After that you will still get more error that Startup class is missing. So include this class.

Now compile the project and you will be able to compile. Lets see the code now

The WebApp.Start is taking a class called Statup as configuration. The configuration defines multiple configuartion paramatere  but here we are only defining the route though which the we will access the REST full API. Now when you run the application you will see a 404 as its still unable to find the values controller. So lets include that.


Now run the app and you will see an output. Wohoo a successful self hosting app.

 Posted by at 10:22 am
Jul 132017

To create your first c# Bot you need to setup your environment you the Bot project template and the Bot framework channel emulator. They are not included in the standard VS installation package (at least not yet) so we have to fix it ourselves. Lets fix the project template first. You can download the project template from this link. After you download the template unzip the template and open this path “C:\Users\usernmae\Documents\Visual Studio 2017\Templates\ProjectTemplates\Visual C#” and paste you unzipped folder here. Once you have that you will be able to see the new Bot project template in your ‘Create New Project’ dialog.

bot new project


Once you have that you can just hit F5 to run but you will notice that it will only open your selected browser nothing else will happen. You need to communicate with your bot and for that you need an emulator. You can download the emulator from here. Once you have that you can run it and along with the hosted application. We will see the emulator in more detail in the next slide.

Bot Framework Channel Emulator

bot emulator empty


 Posted by at 2:59 pm
Jul 122017

Though the concept is really simple but there is always an edge confusion between the two. Lets discuss them one by one using example. To understand the concept of Abstract lets consider one of this easy case domain problem. Lets discuss the characteristics of an animal. An animal can have 4 legs if its a horse and two legs if its a Kangaroo (ok you can argue that the arms are legs as well but lets assume that its only two legs and two arms). When i define a object of such characteristics i cant really say directly that an animal has 4 legs. I mean in real life it could have 4 but not when its a Kangaroo. Let me define the two processes separately

If we have a domain case where we say that we cannot haven’t an object of Animal class because we don’t know if it would have 4 or 6 legs. but we could have Horse or Kangaroo objects. Then we define the animal class abstract. What it will do it one it could restrict the type animal to be instantiated and secondly it would force all the child classes to implement the base class abstract method.

If we have a domain case where we have a Passenger class which could travel with ticket. But if its European passenger then we need to check the passport only and if its Non European passenger then we need to check the Passport and visa. To implement that check the example below where the base class(Passenger) method is overridden by the child class based on their nature






 Posted by at 4:38 pm
Jul 112017

Structs are value types so their memory allocation is stored in Stack in the memory on your computer and the class is stored on heap which is a different location the logical memory. The reason behind that is structs are value types and classes are reference type. So if you pass a struct to a method and change the value of that the object you will see that the value is changed within that scope of the method. On the other hand if you do the same with a class and pass it to a method. In that method if you update the value of the object. You will see that the value of the actual object is also changed. see the example below


The output from that code is

values before passing Asad Mirza
values updated Ali Mirza
values after passing Asad Mirza
Class Object
values before passing Asad Mirza
values updated Ali Mirza
values after passing Ali Mirza

So you see for the class object the actual value is updated

 Posted by at 11:29 am
Jul 102017

In this example i will printing out the list of movies that we get in the form of Json and print them out.

Step1: Create a console project

Step2: Add newtonsoft nuget package

Step3: I will be using a open source api that i will call to pint the title of the movie along with the release year. In this example i will print the movies which have the keyword beast in the title. So here is the code.


In the above code the variable text have the resulting json text. which looks like this

[ { “id”: “5628302”, “title”: “Beast (III)”, “year”: “2017”, “poster”: “N/A”, “type”: “movie” }, { “id”: “6414796”, “title”: “Beast (V)”, “year”: “2017”, “poster”: “N/A”, “type”: “movie” }, { “id”: “4261746”, “title”: “Beast (VIII)”, “year”: “2017”, “poster”: “N/A”, “type”: “movie” }, { “id”: “1365050”, “title”: “Beasts of No Nation”, “year”: “2015”, “poster”: “N/A”, “type”: “movie” }, { “id”: “1152398”, “title”: “Beastly”, “year”: “2011”, “poster”: “N/A”, “type”: “movie” } ]

To deserialize it I will cal the newtonsoft deserializer that will map the json values to my object MovieInfo and provide me with the converted list.

 Posted by at 10:38 am
Jul 072017

You may ask what is the purpose of this post. The title seems really confusing indicating that i may have used the same word twice and trying to explain the difference between it. The thing is these are two different things. One if the native class string and the other is the class object provided by the framework called String. Basically there is no difference in them as  far as the functionality is concerned but when it comes to coding convention then if you want to declare any string value you should use the class ‘string’ to declare it but if you want to use any functionality from the string class the you should use the class ‘String’ which is also the class the object the static class through which you class access method like concat or Parse.

 Posted by at 10:44 pm
Jul 062017

In this post i am going to explain two different ways to parse XML file. I am directly going to start with the code but before that here is my sample XML. In the code there are two ways of parsing the XML one is the simple way of doing it through which it is done using the XMLReader way and the other is to deserialize it to a class. Both are explained below


The code to parse it is

In the above code the first method called from main is ParseXML. In this method we are using the simplest way to parse the XML by using the XMLReader. So first we need to create the XMLReader by providing the content of the XML and once we have that then its really easy to go though the XML. The first method used is ‘ReadToFollowing’ this method will take you to the first requested node and each call will traverse to the next occurrence. It returns a bool type based on the result of the search. MoveToFirstAttrubute read the first attribute of the node.

The other way to parse the XML file is to serialize it in object. But you have to have an class object in which you can map the XML file and for complex object its a bit hard to make it. Luckily VS provides a really easy way to do it. All you have to do is select the XML and do the following process


You will get the following file

In method serializeXML i am using the deserializer to deserialize the XML to catalog object and then i just loop around the list to display





 Posted by at 2:45 pm
Jul 052017

I was always getting confused in what to use until i came to know when should we use IEuqatable and IComparable. So lets say you have an object and you want to use it in a dictionary. Sometime we implement the ‘contains’ method from the dictionary on the list. Now this method wont work if the object is not implementing IEquatable. When you implement that method than the purpose of this method is to compare the object with another object. So indirectly we helped our ‘contains’ method which will use this to compare the object.


Now lets say there is another requirement in which you want to sort the dictionary then then object used in that dictionary should implement IComparable. By using this interface you will have to implement the compareTo method where you will mention the position of the two objects under observation.

 Posted by at 11:30 am
Jul 042017

I realy want to get my hands dirty with the new .Net core hype so i thought may be not its the time. Before going crazy on the visual studio i decided to use the .net core using the command line. So lets start

To begin with you need to have .net installed. If you have VS 2017 then .Net core is already part of it but if you dont have it you can download it from here 

To verify if you have successfully installed .net core open command prompt and run the command dotnet you will get this


I will do it in certain steps so that it is more clear

Step 1:

Lets create a directory where we work in so i will create a new directory called ‘dotnetHelloWorld’


Step 2:

Lets create our first project. Now we can create differnt types of project in c#, F# and VB but lets start by creating a C# console project and for that we need to run the command ‘dotnet new console’.


In our directory there will be two files created



Now lets build the project so for that we need to run the command ‘dotnet build’ and when i did that i got some errors. if you see the error list it complains about the types not defined and it cannot find the library for those system types


To fix that we need to restore before build which will restore all the required nuget packages. So run ‘dotnet restore’


Step 4:

Lets give another try to build the project so run ‘dotnet build’ and you will get this


After building now we will try to run it and if you notice the file structure there is no exe file generated in the bin folder that you can double click and run its only the pdb and the dll as .net core will generate the libraries so how to run it? Well dotnet core have solved this problem by giving a command so if you run ‘dotnet run’ you will see the output.




The reason to use it via the command is that it could be used on any platform and could be really handy on build machines.



 Posted by at 4:40 pm
Jul 032017

A quick reference on how you can use tasks. I wont write much around here as the code is explaining it self. The name of the methods tell the action around the task, how they were created and what is the purpose of that code. This is really basic code snippet right now but i will write more around that and more detailed code


 Posted by at 12:59 pm