A day with .Net

My day to day experince in .net

Moving your app to free service plan in microsoft azure.

Posted by vivekcek on November 11, 2016

I was working on a research project with a developer essentials account in azure.
The first problem i faced was to deploy the app from visual studio ,immediately after creating my subscription.
So i just logged in to the portal and created a Web App, unfortunately i forgot to select the free pricing tier.

After someday’s i found that my credit is going down, from the bill it was found that the app service is consuming all money.

Immediately i had to do something. I tried the below steps.

1. Created a new app in the same resource group with a new service plan and free pricing tier.
2. Then i changed the service plan of my existing app to new free service plan.
3. Then tried to delete my old service plan.
4. Haaaa got the error, i can’t delete this plan due to an app is associated with it.
5. But there was no app associated with that plan.
6. After some reserach i found that it is the resource group is causing the issue.
7. I can’t delete my existing default resource group, as my existing app and free service plan is running above it.
8. Now i created a new Resource group and moved my old service plan to this group.
9. Then i was able to delete my old plan and my app is now running freely.

Moving Service plan to new resource group

Deleteing the resource group.



Posted in Azure | Tagged: | Leave a Comment »

Amzon AWS Windows Server 2016 hosting -Could not write to output file

Posted by vivekcek on November 2, 2016

I was trying to host an ASP.NET 4.5 application in an Amazon EC2 instance (Windows Server 2016)

Then i got below error

CS0016: Could not write to output file ‘c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\6a5d994b\b5f46f1c\App_global.asax.o34wdr3q.dll’ — ‘Access is denied. ‘

We can solve this by below power shell script

$dir = "C:\Windows\Temp"
$acl = get-acl -path $dir
$new = "IIS_IUSRS","FullControl","ContainerInherit,ObjectInherit","None","Allow"
$accessRule = new-object System.Security.AccessControl.FileSystemAccessRule $new
$acl | Set-Acl $dir

Posted in Amazon AWS | Tagged: , | Leave a Comment »

Angular 2 Routing And Passing Parameters

Posted by vivekcek on October 30, 2016

When we plan to develop an Angaular2 application, the first thing need to be in place is a good routing module.
So the intention of this post is to help developers to design a routing mechanism for their Angular2 App.

Hope the reader have some good understanding of Angular2 basics like Module, Component, Routing etc.

We are going to develop an app that have 2 pages ‘Home’ and ‘Products’.
The Home page contain a textbox and a button. Once we enter some value in the textbox and click the button,
products page will be displayed with the value we entered in the home page.

So this post also demonstrate, how you can pass value from one component to another via routing.

Let us have a look at the UI.

Home Page

Products Page


We have 3 components in our app.

1. AppComponent (Which is our root component).
2. HomeComponent
3. ProductListComponent

Now follow these steps:

1. First let us create our Routing Module.

import { NgModule } from '@angular/core'
import { RouterModule, Routes} from '@angular/router'

import { HomeComponent } from './home.component'
import {ProductListComponent} from './product-list.component'

const routes:Routes=[
    { path:'', redirectTo:'/home', pathMatch:'full' },
    { path:'home', component:HomeComponent },
    {path:'products/:value', component:ProductListComponent}



export class AppRoutingModule{}

2. Integrate our routing module to main AppModule.

import {NgModule} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import {FormsModule} from '@angular/forms'
import{AppRoutingModule} from './app-routing.module'

import {AppComponent} from './app.component'
import {HomeComponent} from './home.component'
import {ProductListComponent} from './product-list.component'


export class AppModule{}

3. Add as the first child of head.


4. Define route links and outlet in our root component (AppComponent)

import { Component} from '@angular/core'

    <a routerLink='/home'>Home</a>
    <a [routerLink]="['/products','test']">Products</a>

export class AppComponent{
    Title:string='Routing Demo';

5. Here is th code for HomeComponent

import {Component} from '@angular/core'
import {Router} from '@angular/router'

export class HomeComponent{
    constructor(private router:Router){


        let link=['/products',value];

6. Here is the code for home.html

<input #input/>
<button (click)="Go(input.value)">Next Page</button>

7. Here is the code for ProductListComponent

import {Component,OnInit} from '@angular/core'
import{ActivatedRoute,Params} from '@angular/router'
import{Location} from '@angular/common'

export class ProductListComponent implements OnInit{
    Title:string='Product List';
    constructor(private router:ActivatedRoute,
    private location:Location){}



8. Here is the code for products.html

<label>Passed Value is {{Input}}</label>

So you are done.

Download code from https://github.com/vivekcek/AngularCRUD

Posted in Angular2 | Tagged: , , | Leave a Comment »

Desktop application with Angular2 and Electron in One minute

Posted by vivekcek on October 24, 2016

We can use Angular2 and electron to build nice desktop application for Windows/Mac/Linux.
So how to do it in a minute

1. Install visual studio code.
2. Install Node package manager.
3. Clone the code from my git hub.


4. Run command “npm install”
5. Run command “npm start” or debug with VS Code.
6. Please set the path in launch.json, and point to electron module.



Posted in Angular2 | Tagged: | Leave a Comment »

Angular2 Development With Visual Studio Code

Posted by vivekcek on October 24, 2016

In this post, i will show you how we can use VS Code for Angular2 development.
The main thing is how to configure VS Code to transpile typescript to js files and lunch the app.

1. Install NodeJs
2. Install visual studio code.
3. Install TypeScript via NPM (Visual studio code may normally install TypeScript).
4. Create a folder in E, E:\Angular2
5. Open this folder through VS Code.
6. Go to https://angular.io/docs/ts/latest/quickstart.html
7. Create 3 files in VS Code , package.json, tsconfig.json, systemjs.config.js.
8. From angular site copy the codes for these files and save.
9. Go to NPM and change your directory to E:\Angular2, and issue below command

npm install


10. Now create a folder named app, and create below files (Refer angular2 quick start).

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent }   from './app.component';
  imports:      [ BrowserModule ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
export class AppModule { }
import { Component } from '@angular/core';
  selector: 'my-app',
  template: '<h1>My First Angular App</h1>'
export class AppComponent { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
const platform = platformBrowserDynamic();
    <title>Angular QuickStart</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="styles.css">
    <!-- 1. Load libraries -->
     <!-- Polyfill(s) for older browsers -->
    <script src="node_modules/core-js/client/shim.min.js"></script>
    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/reflect-metadata/Reflect.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <!-- 2. Configure SystemJS -->
    <script src="systemjs.config.js"></script>
      System.import('app').catch(function(err){ console.error(err); });
  <!-- 3. Display the application -->


11. So everything is ready, now important step to configure TypeScript compiler.
12. Ctrl+Shift+P will open command pallette.
13. Type task and select Configure Task Runner
14. Selecet tsconfig.json
15. This will create a file named tasks.json, update args section as shown in image (args:[])
16. Now click on build and configure launch.json file.
17. Update program section as shown.
18. Run the app now

Posted in Uncategorized | Tagged: , | Leave a Comment »

Write ECMAScript 6 (JavaScript 6) in VS Code.

Posted by vivekcek on October 9, 2016

In this post i will show you how to write and debug EcmaScript6 in VS Code.

1. Install NodeJs (Check the configure path option during install).
2. Install VS Code.
3. Restart your machine/Inspect path has been set for NodeJs.
4. Start VS Code.
5. From menu select Open Folder(File->Open Folder).

6. Create a New Folder.

7. Create a new file named “jsconfig.json” and paste below code.

    "compilerOptions": {
        "target": "ES6"


8. Now create a javascript file Hello.js and paste below code.

class Car {
    constructor(make) { //constructors!
        this.make = make;
      this.currentSpeed = 25;

          console.log(this.make + ' is going ' + this.currentSpeed + ' mph.');

class RaceCar extends Car { //inheritance
    constructor(make, topSpeed) {
        super(make); //call the parent constructor with super
        this.topSpeed = topSpeed;

          this.currentSpeed = this.topSpeed;

let stang = new RaceCar('Mustang', 150);



9. From menu select Debug (View->Debug).


10. Click on green start debug button, which will ask to configure the settings.
Select NodeJs


11. When we select NodeJs,VS Code will open launch.json. Update it with our file name Hello.js


12 Agin click on that Green Play button and enjoy.


Posted in javascript | Tagged: , , , | Leave a Comment »

Restart Amazon AWS EC2 instance from PowerShell

Posted by vivekcek on July 25, 2016

In this post i will show you how can we restart a windows ec2 instance by using powershell.

1. Go to your account, select Security Credentials and create an AWS access key and secret key.



2. Open Power-Shell for AWS, which will ask your AWS Access key and Secret Key.


3. If Power-Shell not prompted for keys go to “C:\Users\Administrator\AppData\Local\AWSToolkit” and delete the Registered Account Jsonfile and open Power-Shell again.

4. Now get your instance id by using this url from EC2 instance

5. Now from powershell give below command

Restart-EC2Instance -InstanceId i-12345678

Posted in Amazon AWS | Tagged: , , , | Leave a Comment »

C# Different Types Of Heap Memory

Posted by vivekcek on July 10, 2016

You might be heard that, reference objects are stored in heap:).
Do you know how many types of heaps are available in CLR.
Do you know that, you can pass data to another app domain with out marshaling:)

These all are .NET CLR implementation details, know to Bill Gates:)

You can explore, if you want to know more, Later i will post about memory management in CLR.

For the time being have a look at the types of heap’s below.

Loader Heap: contains CLR structures and the type system
High Frequency Heap: statics, MethodTables, FieldDescs, interface map
Low Frequency Heap: EEClass, ClassLoader and lookup tables
Stub Heap: stubs for CAS, COM wrappers, PInvoke
Large Object Heap: memory allocations that require more than 85k bytes
GC Heap: user allocated heap memory private to the app
JIT Code Heap: memory allocated by mscoreee (Execution Engine) and the JIT compiler for managed code
Process/Base Heap: interop/unmanaged allocations, native memory, etc

Usually, the “heaps” that most people refer to or know about are the “GC Heap” and the LOH.
GC Heap is shared among app-domains and GC will work only on that.


Posted in c#.net | Tagged: , , , , , , , , | Leave a Comment »

Filter datatable based on coulmns

Posted by vivekcek on June 26, 2016

If you want to build a new table from an existing table, with some columns try this

var selectedColumns = new[] {"Coulmn1","Coulmn2" };
var newTable = new DataView(oldTable).ToTable(false, selectedColumns);

Posted in c#.net | Tagged: | Leave a Comment »

Get non empty rows from a datatable

Posted by vivekcek on June 26, 2016

If you want to filter out empty rows from a datatable try this tipe

var nonEmptyRows = MyTable.Rows.Cast<DataRow>()
                                                row =>
                                                        field =>
                                                            field is System.DBNull ||
                                                            string.Compare((field as string).Trim(), string.Empty) == 0));
            MyTable = nonEmptyRows.Any() ? nonEmptyRows.CopyToDataTable() : MyTable.Clone();

Posted in c#.net | Tagged: , | Leave a Comment »