Salı, 29 Mayıs 2018 / Published in Uncategorized


In this article, I will demonstrate how to implement Google Line Chart dynamically using Entity Framework in ASP.NET. I will use jQuery AJAX to retrieve the data from the database and display in Google Line Chart. The chart will display the respective data on its point line with an animation.

Step 1 Open SQL server 2014 and create a database table to insert the data and retrieve data.

  1. CREATE TABLE [dbo].[CompanyHiringReport](  
  2.     [ID] [int] IDENTITY(1,1) NOT NULL,  
  3.     [Year] [intNULL,  
  4.     [Account] [intNULL,  
  5.     [HR] [intNULL,  
  6.     [IT] [intNULL,  
  7.     [Sales] [intNULL,  
  8.     [Marketing] [intNULL,  
  10. (  
  11.     [ID] ASC  
  13. ON [PRIMARY]  
  15. GO  

Step 2Open Visual Studio 2015, click on New Project, and create an empty web application project.

Screenshot for creating new project 1


After clicking on New Project, one window will appear; select Web from left panel, choose ASP.NET Web Application, give a meaningful name to your project. Then, click on OK as shown in the below screenshot.

Screenshot for creating new project 2


After clicking on OK, one more window will appear. Choose Empty, check on Web Forms checkbox, and click on OK.

Screenshot for creating new project 3


Step 3Click on Tools, select NuGet Package Manager, then choose Manage NuGet Packages for Solution click on it.

Screenshot for NuGet Package


After that, a window will appear. Choose Browse type  as bootstrap and install the package in the project.

 Similarly, type jQuery and install the latest version of jQuery package in the project from NuGet, then close NuGet Solution.

 Keep the useful file in Content and scripts folder as shown below.

Step 4Add Entity Framework, right click on Models folder, select Add >> New Item and click on it.

Screenshot for adding entity framework 1


After clicking on New item, you will get a window. From there, select Data from the left panel and choose ADO.NET Entity Data Model, give it the name DBModels (this name is not mandatory; you can give any name), then click on Add.

Screenshot for adding entity framework 2


After you click on Add, a window wizard will open. Choose EF Designer from the database and click Next.

Screenshot for adding entity framework 3

After clicking on Next, a window will appear. Choose New Connection.

Screenshot for adding entity framework 4


Another window will appear. Add your server name if it is local then enter dot (.). Choose your database and click on OK.

Screenshot for adding entity framework 5


A connection will get added. If you wish, save it as you like. You can change the name of your connection below. It will save the connection in web config, then click on Next.

Screenshot for adding entity framework 6


After clicking on NEXT, another window will appear. Choose database table name as shown in the below screenshot. Then, click on Finish. Entity Framework will be added with the respective class which gets generated under Models folder.

Screenshot for adding entity framework 7

Screenshot for adding entity framework 8

Following class will be added.

  1. namespace GoogleLineChart_Demo.Models  
  2. {  
  3.     using System;  
  4.     using System.Collections.Generic;  
  6.     public partial class CompanyHiringReport  
  7.     {  
  8.         public int ID { get; set; }  
  9.         public Nullable<int> Year { get; set; }  
  10.         public Nullable<int> Account { get; set; }  
  11.         public Nullable<int> HR { get; set; }  
  12.         public Nullable<int> IT { get; set; }  
  13.         public Nullable<int> Sales { get; set; }  
  14.         public Nullable<int> Marketing { get; set; }  
  15.     }  
  16. }  

Step 5 Right click on the project, select Add, choose Web Form and click on it.


After clicking on the web form, one window will appear. Give it a meaningful name and click on OK.

Step 6 Right click on Scripts folder, select Add, choose JavaScript File, then click on it.

After clicking on the JavaScript file a window will appear. Give it the name LineChart, then click on OK.

Add the following jQuery and JavaScript code to retrieve data from the database and display it in the chart.

  1. var chartData; // globar variable for hold chart data  
  2. google.load("visualization""1", { packages: ["corechart"] });  
  3. // Here We will fill chartData  
  4. $(document).ready(function () {  
  5.     $.ajax({  
  6.         url: "GoogleLineChart.aspx/GetChartData",  
  7.         data: "",  
  8.         dataType: "json",  
  9.         type: "POST",  
  10.         contentType: "application/json; chartset=utf-8",  
  11.         success: function (data) {  
  12.             chartData = data.d;  
  13.         },  
  14.         error: function () {  
  15.             alert("Error loading data! Please try again.");  
  16.         }  
  17.     }).done(function () {  
  18.         // after complete loading data  
  19.         google.setOnLoadCallback(drawChart);  
  20.         drawChart();  
  21.     });  
  22. });  
  23. function drawChart() {  
  24.     var data = google.visualization.arrayToDataTable(chartData);  
  25.     var options = {  
  26.         title: "Company Hiring Report",  
  27.         pointSize: 5  
  28.     };  
  29.     var lineChart = new google.visualization.LineChart(document.getElementById(‘chart_div’));  
  30.     lineChart.draw(data, options);  
  31. }  

Step 7 Add the following scripts and styles in the head section of the web form.

  1. <link rel="stylesheet" href="">  
  2.  “text/javascript” src=“”>  
  3.  <link href="Content/bootstrap.min.css" rel="stylesheet" />  
  4.  “scripts/jquery-3.3.1.min.js”>  
  5.  “scripts/bootstrap.min.js”>  
  6.  “scripts/LineChart.js”>  

Step 8 Design the web form using textbox control, button control, and GridView control and Bootstrap 4 class to look good.

  1. <body>  
  2.     <form id="form1" runat="server">  
    class=“container py-4”>  
    class=“text-center text-uppercase”>How to Implement Google Line Chart Dynamically Using Entity Framework in Asp.Net


    class=“card-header bg-primary”>  
    class=” text-upparcase text-white”>Company Hiring Report




    class=“modal fade” id=“CompantReport”>  
    class=“modal-dialog modal-lg”>  

    class=“modal-title”>New Hiring Report



  •                                                 “txtYear” CssClass=“form-control” runat=“server”>  
  •                                                 “rfvYear” ControlToValidate=“txtYear” CssClass=“text-danger” runat=“server” ErrorMessage=“Please enter year”>  

  •                                         </div>  
  •                                                 “txtAccountDepartment” CssClass=“form-control” runat=“server”>  
  •                                                 “rfvAccount” ControlToValidate=“txtYear” CssClass=“text-danger” runat=“server” ErrorMessage=“Please enter number employee hired”>  

  •                                         </div>  
  •                                                 “txtHRDepartment” CssClass=“form-control” runat=“server”>  
  •                                                 “rfvHR” ControlToValidate=“txtHRDepartment” CssClass=“text-danger” runat=“server” ErrorMessage=“Please enter number employee hired”>  

  •                                         </div>  
  •                                     </div>  
  •                                                 “txtITDepartment” CssClass=“form-control” runat=“server”>  
  •                                                 “rfvIT” ControlToValidate=“txtITDepartment” CssClass=“text-danger” runat=“server” ErrorMessage=“Please enter number employee hired”>  

  •                                         </div>  
  •                                                 “txtSalesDepartment” CssClass=“form-control” runat=“server”>  
  •                                                 “rfvSales” ControlToValidate=“txtSalesDepartment” CssClass=“text-danger” runat=“server” ErrorMessage=“Please enter number employee hired”>  

  •                                         </div>  
  •                                                 “txtMarketingDepartment” CssClass=“form-control” runat=“server”>  
  •                                                 “rfvMarketing” ControlToValidate=“txtMarketingDepartment” CssClass=“text-danger” runat=“server” ErrorMessage=“Please enter number employee hired”>  

  •                                         </div>  
  •                                     </div>  
  •                                 </div>  
  •                                     “btnSubmit” CssClass=“btn btn-primary rounded-0” runat=“server” Text=“Submit” OnClick=“btnSubmit_Click” />  

  •                             </div>  
  •                         </div>  
  •                     </div>  
  •                     <asp:GridView ID="CompanyGridView" AutoGenerateColumns="false" runat="server" CssClass="table table-bordered table-striped">  
  •                         <Columns>  
  •                             <asp:BoundField HeaderText="ID" DataField="ID" />  
  •                             <asp:BoundField HeaderText="Year" DataField="Year" />  
  •                             <asp:BoundField HeaderText="Account Department" DataField="Account" />  
  •                             <asp:BoundField HeaderText="HR Department" DataField="HR" />  
  •                             <asp:BoundField HeaderText="IT Department" DataField="IT" />  
  •                             <asp:BoundField HeaderText="Sales Department" DataField="Sales" />  
  •                             <asp:BoundField HeaderText="Marketing Department" DataField="Marketing" />  
  •                         </Columns>  
  •                     </asp:GridView>  
  •                 </div>  
  •             </div>   
    “chart_div” style=“width: 100%; height: 400px”>  


  •         </div>  
  •     </form>  
  • </body>  
  • Step 9 Double click on the submit button and write the following C# code.

    Add the following namespace.

    1. using System;  
    2. using System.Collections.Generic;  
    3. using System.Linq;  
    4. using System.Web.Script.Services;  
    5. using System.Web.Services;  
    6. using System.Web.UI.WebControls;  
    7. using GoogleLineChart_Demo.Models; 

    Complete C# code of web form

    1. using System;  
    2. using System.Collections.Generic;  
    3. using System.Linq;  
    4. using System.Web.Script.Services;  
    5. using System.Web.Services;  
    6. using System.Web.UI.WebControls;  
    7. using GoogleLineChart_Demo.Models;  
    9. namespace GoogleLineChart_Demo  
    10. {  
    11.     public partial class GooglelineChart : System.Web.UI.Page  
    12.     {  
    13.         protected void Page_Load(object sender, EventArgs e)  
    14.         {  
    15.             if (!IsPostBack)  
    16.             {  
    17.                 BindGridView();  
    18.                 ClearTextBox();  
    19.             }  
    20.         }  
    22.         private void ClearTextBox()  
    23.         {  
    24.             txtYear.Text = string.Empty;  
    25.             txtAccountDepartment.Text = string.Empty;  
    26.             txtHRDepartment.Text = string.Empty;  
    27.             txtITDepartment.Text = string.Empty;  
    28.             txtSalesDepartment.Text = string.Empty;  
    29.             txtMarketingDepartment.Text = string.Empty;  
    30.         }  
    32.         private void BindGridView()  
    33.         {  
    34.             using (DBModel db = new DBModel())  
    35.             {  
    36.                 CompanyGridView.DataSource = (from r in db.CompanyHiringReports select r).ToList();  
    37.                 CompanyGridView.DataBind();  
    38.             }  
    39.         }  
    41.         [WebMethod]  
    42.         [ScriptMethod(ResponseFormat = ResponseFormat.Json)]  
    43.         public static object[] GetChartData()  
    44.         {  
    45.             List<CompanyHiringReport> data = new List<CompanyHiringReport>();  
    46.             using (DBModel db = new DBModel())  
    47.             {  
    48.                 data = db.CompanyHiringReports.ToList();  
    49.             }  
    50.             var chartData = new object[data.Count + 1];  
    51.             chartData[0] = new object[]{  
    52.                 "Year",  
    53.                 "Accounts",  
    54.                 "HR",  
    55.                 "IT",  
    56.                 "Sales",  
    57.                 "Marketing"  
    58.             };  
    59.             int j = 0;  
    60.             foreach (var i in data)  
    61.             {  
    62.                 j++;  
    63.                 chartData[j] = new object[] { i.Year.ToString(), i.Account, i.HR, i.IT,i.Sales,i.Marketing };  
    64.             }  
    65.             return chartData;  
    66.         }  
    68.         protected void btnSubmit_Click(object sender, EventArgs e)  
    69.         {  
    70.             using (DBModel db = new DBModel())  
    71.             {  
    72.                 CompanyHiringReport company = new CompanyHiringReport();  
    73.                 company.Year = Convert.ToInt32(txtYear.Text);  
    74.                 company.Account = Convert.ToInt32(txtAccountDepartment.Text);  
    75.                 company.HR = Convert.ToInt32(txtHRDepartment.Text);  
    76.                 company.IT = Convert.ToInt32(txtITDepartment.Text);  
    77.                 company.Sales = Convert.ToInt32(txtSalesDepartment.Text);  
    78.                 company.Marketing = Convert.ToInt32(txtMarketingDepartment.Text);  
    80.                 db.CompanyHiringReports.Add(company);  
    81.                 db.SaveChanges();  
    82.                 ClearTextBox();  
    83.             }  
    84.             this.BindGridView();  
    85.         }  
    86.     }  
    87. }  

    Step 9 Right click on web config file and add the following code to avoid validation related errors.

    1. <appSettings>  
    2.   <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />  
    3. </appSettings>  

    Step 10 Run project by pressing ctrl+F5.

    Screenshot 1

    Screenshot 2



    In this article, I have explained how to implement Google Line Chart dynamically using Entity Framework in ASP.NET. We can add yearly reports and department names by clicking on Add New Report button. We have understood it step by step. I hope it will be useful in your upcoming projects.

    Salı, 29 Mayıs 2018 / Published in Uncategorized

    WPF Window With Buttons In Toolbar Preview

    Today, in this article, I will explain how to add buttons in Application toolbar preview window,  as you may have seen in Windows Media Player, as shown below.



    This is very simple, but still many developers do not know about it. 

    Step 1

    Create a WPF application and in App.xaml file place the below code in the Resource section.

    1. <DrawingImage x:Key="Rocket">  
    2.             <DrawingImage.Drawing>  
    3.                 <DrawingGroup ClipGeometry="M0,0 V128 H128 V0 H0 Z">  
    4.                     <DrawingGroup>  
    5.                         <DrawingGroup>  
    6.                             <GeometryDrawing Brush="#FFF68C29" Geometry="F1 M128,128z M0,0z M83.5,85.6C82.9,85 82.9,84.1 83.5,83.5 84.1,82.9 85,82.9 85.6,83.5L94.4,92.5C95,93.1 95,94 94.4,94.6 93.8,95.2 92.9,95.2 92.3,94.6L83.5,85.6z" />  
    7.                             <GeometryDrawing Brush="#FFF68C29" Geometry="F1 M128,128z M0,0z M76.6,92.5C76,92 76,91 76.6,90.4 77.2,89.8 78.1,89.8 78.7,90.4L90.4,102.3C91,102.9 91,103.8 90.4,104.4 89.8,105 88.9,105 88.3,104.4L76.6,92.5z" />  
    8.                             <GeometryDrawing Brush="#FFF68C29" Geometry="F1 M128,128z M0,0z M90.4,78.7C89.8,78.1 89.8,77.2 90.4,76.6 91,76 91.9,76 92.5,76.6L104.2,88.5C104.8,89.1 104.8,90 104.2,90.6 103.6,91.2 102.7,91.2 102.1,90.6L90.4,78.7z" />  
    9.                             <GeometryDrawing Brush="#FFF7D309" Geometry="F0 M128,128z M0,0z M26.5,26.5L26.5,26.5C32.5,20.5,42.3,20.5,48.3,26.5L91.5,69.7C93.7,71.9,93.7,75.5,91.5,77.7L77.7,91.5C75.5,93.7,71.9,93.7,69.7,91.5L26.5,48.3C20.5,42.3,20.5,32.5,26.5,26.5z" />  
    10.                             <GeometryDrawing>  
    11.                                 <GeometryDrawing.Brush>  
    12.                                     <SolidColorBrush Color="#FF002535" Opacity="1" Transform="-0.7071,-0.7071,0.7071,-0.7071,41.5737,100.3503" />  
    13.                                 </GeometryDrawing.Brush>  
    14.                                 <GeometryDrawing.Geometry>  
    15.                                     <RectangleGeometry RadiusX="0" RadiusY="0" Rect="35.7,26.1,11.7,30.9" Transform="-0.7071,-0.7071,0.7071,-0.7071,41.5737,100.3503" />  
    16.                                 </GeometryDrawing.Geometry>  
    17.                             </GeometryDrawing>  
    18.                             <GeometryDrawing>  
    19.                                 <GeometryDrawing.Brush>  
    20.                                     <SolidColorBrush Color="#FF002535" Opacity="1" Transform="-0.7071,-0.7071,0.7071,-0.7071,78.5369,189.5846" />  
    21.                                 </GeometryDrawing.Brush>  
    22.                                 <GeometryDrawing.Geometry>  
    23.                                     <RectangleGeometry RadiusX="0" RadiusY="0" Rect="75.6,63.1,5.8,30.9" Transform="-0.7071,-0.7071,0.7071,-0.7071,78.5369,189.5846" />  
    24.                                 </GeometryDrawing.Geometry>  
    25.                             </GeometryDrawing>  
    26.                             <GeometryDrawing Brush="#FFE0ECC1">  
    27.                                 <GeometryDrawing.Geometry>  
    28.                                     <EllipseGeometry RadiusX="10.6" RadiusY="10.6" Center="57.1,57.1" />  
    29.                                 </GeometryDrawing.Geometry>  
    30.                             </GeometryDrawing>  
    31.                             <GeometryDrawing Brush="#FF002535" Geometry="F1 M128,128z M0,0z M57.1,48.1C54.8,48.1,52.5,49,50.7,50.8L50.7,50.8C48.9,52.6 48,54.9 48,57.2 48,59.5 48.9,61.8 50.7,63.6L50.7,63.6C52.5,65.4 54.8,66.3 57.1,66.3 59.4,66.3 61.7,65.4 63.5,63.6L63.5,63.6C65.3,61.8 66.2,59.5 66.2,57.2 66.2,54.9 65.3,52.6 63.5,50.8L63.5,50.8C61.8,48.9,59.5,48.1,57.1,48.1z M48.6,48.6C51,46.2 54,45.1 57.1,45.1 60.2,45.1 63.3,46.3 65.6,48.6L65.6,48.6C68,51 69.1,54 69.1,57.1 69.1,60.2 67.9,63.3 65.6,65.6L65.6,65.6C63.2,68 60.2,69.1 57.1,69.1 54,69.1 50.9,67.9 48.6,65.6L48.6,65.6C46.2,63.2 45.1,60.2 45.1,57.1 45.1,54 46.3,51 48.6,48.6L48.6,48.6z" />  
    32.                             <GeometryDrawing Brush="#FFE53839" Geometry="F1 M128,128z M0,0z M63.3,85.2C58,90.5 59.2,98 63.8,106 37.7,85 52,73.9 52,73.9L63.3,85.2z" />  
    33.                             <GeometryDrawing Brush="#FFEE464A" Geometry="F1 M128,128z M0,0z M85.1,63.3C90.4,58 97.9,59.2 105.9,63.8 85,37.7 73.9,52 73.9,52L85.1,63.3z" />  
    34.                             <GeometryDrawing Brush="#FFDBBC26" Geometry="F0 M128,128z M0,0z M65.7,65.7C63.3,68.1 60.3,69.2 57.2,69.2 54.1,69.2 51,68 48.7,65.7 46.3,63.3 45.2,60.3 45.2,57.2 45.2,54.1 46.4,51 48.7,48.7L45.8,45.8 34.8,56.6 63.3,85.1 65.5,87.3 76.4,76.4 65.7,65.7z" />  
    35.                             <GeometryDrawing Brush="#FFDBBC26" Geometry="F0 M128,128z M0,0z M80.6,80.6L69.7,91.5C71.5,93.3 74.3,93.6 76.5,92.4 76.9,92.2 77.3,91.9 77.7,91.5L78.8,90.4 83.6,85.6 84.7,84.5 83.6,83.4 80.6,80.6z" />  
    36.                             <GeometryDrawing Brush="#FFDBBC26" Geometry="F0 M128,128z M0,0z M26.5,48.3L37.4,37.4 26.5,26.5C20.5,32.5,20.5,42.3,26.5,48.3z" />  
    37.                         </DrawingGroup>  
    38.                     </DrawingGroup>  
    39.                 </DrawingGroup>  
    40.             </DrawingImage.Drawing>  
    41.         </DrawingImage>  
    42.         <DrawingImage x:Key="Boat">  
    43.             <DrawingImage.Drawing>  
    44.                 <DrawingGroup ClipGeometry="M0,0 V128 H128 V0 H0 Z">  
    45.                     <DrawingGroup>  
    46.                         <DrawingGroup>  
    47.                             <GeometryDrawing Brush="#FFECE46F" Geometry="F0 M128,128z M0,0z M18.5,87.5L108.3,87.5C109.5,87.5,110.5,88.5,110.5,89.7L110.5,108.6 37.7,108.6C26.6,108.6,17.5,99.5,17.5,88.4L17.5,88.4C17.6,87.9,18,87.5,18.5,87.5z" />  
    48.                             <GeometryDrawing Brush="#FFF7D309" Geometry="F0 M128,128z M0,0z M69.1,22.8L69.1,87.5 52.4,87.5 35.8,87.5C36,63.1,42.7,38.1,69.1,22.8z" />  
    49.                             <GeometryDrawing Brush="#FFDBBC26" Geometry="F0 M128,128z M0,0z M72.3,39.6L72.3,39.6 72.1,87.5 88.8,87.5 102.8,87.5z" />  
    50.                             <GeometryDrawing Brush="#FFD2CB60" Geometry="F0 M128,128z M0,0z M110.4,99.1L20.7,99.2C24.3,104.8,30.6,108.5,37.7,108.5L110.4,108.5 110.4,99.1z" />  
    51.                             <GeometryDrawing Brush="#FF005E5D" Geometry="F0 M128,128z M0,0z M69.1,87.5L72.3,87.5 72.3,21C72.3,20.1,71.6,19.4,70.7,19.4L70.7,19.4C69.8,19.4,69.1,20.1,69.1,21L69.1,87.5z" />  
    52.                         </DrawingGroup>  
    53.                     </DrawingGroup>  
    54.                 </DrawingGroup>  
    55.             </DrawingImage.Drawing>  
    56.         </DrawingImage>  
    57.         <DrawingImage x:Key="Balloon">  
    58.             <DrawingImage.Drawing>  
    59.                 <DrawingGroup ClipGeometry="M0,0 V128 H128 V0 H0 Z">  
    60.                     <DrawingGroup>  
    61.                         <DrawingGroup>  
    62.                             <GeometryDrawing Brush="#FF002535" Geometry="F1 M128,128z M0,0z M49.1,62.4C49.1,61.6 49.7,61 50.5,61 51.3,61 51.9,61.6 51.9,62.4L51.8,80.5C51.8,81.3 51.2,81.9 50.4,81.9 49.6,81.9 49,81.3 49,80.5L49.1,62.4z" />  
    63.                             <GeometryDrawing Brush="#FF002535" Geometry="F1 M128,128z M0,0z M76.1,62.4C76.1,61.6 76.7,61 77.5,61 78.3,61 78.9,61.6 78.9,62.4L78.8,80.5C78.8,81.3 78.2,81.9 77.4,81.9 76.6,81.9 76,81.3 76,80.5L76.1,62.4z" />  
    64.                             <GeometryDrawing Brush="#FF002535" Geometry="F1 M128,128z M0,0z M22.6,62.9C22,62.4 21.9,61.5 22.4,60.9 22.9,60.3 23.8,60.2 24.4,60.7L48.8,81.6C49.4,82.1 49.5,83 49,83.6 48.5,84.2 47.6,84.3 47,83.8L22.6,62.9z" />  
    65.                             <GeometryDrawing Brush="#FF002535" Geometry="F1 M128,128z M0,0z M79.7,83.9C79.1,84.4 78.2,84.3 77.7,83.7 77.2,83.1 77.3,82.2 77.9,81.7L103.6,60.8C104.2,60.3 105.1,60.4 105.6,61 106.1,61.6 106,62.5 105.4,63L79.7,83.9z" />  
    66.                             <GeometryDrawing Brush="#FFF7D309" Geometry="F0 M128,128z M0,0z M55,80.5L73,80.5C75.4,80.5,77.4,82.5,77.4,84.9L77.4,103C77.4,105.4,75.4,107.4,73,107.4L55,107.4C52.6,107.4,50.6,105.4,50.6,103L50.6,84.9C50.5,82.5,52.5,80.5,55,80.5z" />  
    67.                             <GeometryDrawing Brush="#FFDBBC26" Geometry="F0 M128,128z M0,0z M48.8,85.1L77.9,85.1C79.2,85.1,80.2,84.1,80.2,82.8L80.2,82.8C80.2,81.5,79.2,80.5,77.9,80.5L48.8,80.5C47.5,80.5,46.5,81.5,46.5,82.8L46.5,82.8C46.5,84.1,47.5,85.1,48.8,85.1z" />  
    68.                             <GeometryDrawing Brush="#FFE0ECC1" Geometry="F0 M128,128z M0,0z M50.5,63.9L50.5,63.9C49.7,63.9,49.1,63.3,49.1,62.5L49.1,62.5 49.1,62.5C49.1,59.2 47.7,56.1 45.6,53.9 43.4,51.7 40.4,50.4 37,50.4 33.7,50.4 30.8,51.7 28.6,53.8 26.4,55.9 25,58.8 24.9,62 24.9,62.8 24.2,63.4 23.4,63.3 22.6,63.3 22,62.6 22.1,61.8L22.1,61.8C22.3,50.4 27,40.1 34.6,32.6 42.2,25.1 52.6,20.5 64,20.5 75.5,20.5 85.9,25.1 93.4,32.6 101,40.1 105.7,50.4 105.9,61.8L105.9,61.8 105.9,61.8 105.9,61.8C105.9,62.6 105.3,63.2 104.5,63.2 103.7,63.2 103.1,62.6 103.1,61.9L103.1,61.9C103,58.7 101.6,55.8 99.4,53.7 97.2,51.6 94.3,50.3 91,50.3 87.7,50.3 84.6,51.7 82.4,53.8 80.2,56 78.9,59 78.9,62.4L78.9,62.4 78.9,62.4C78.9,63.2,78.3,63.8,77.5,63.8L77.5,63.8 77.5,63.8 77.5,63.8C76.7,63.8,76.1,63.2,76.1,62.4L76.1,62.4 76.1,62.4C76.1,59.1 74.7,56 72.6,53.8 70.4,51.6 67.4,50.3 64,50.3 60.7,50.3 57.6,51.7 55.4,53.8 53.2,56 51.9,59 51.9,62.4L51.9,62.4 51.9,62.4C51.9,63.2,51.3,63.9,50.5,63.9L50.5,63.9 50.5,63.9z" />  
    69.                             <GeometryDrawing Brush="#FFEE464A" Geometry="F0 M128,128z M0,0z M34.6,32.6C27,40.1,22.3,50.4,22.1,61.8L22.1,61.8C22.1,62.6 22.7,63.2 23.4,63.3 23.8,63.3 24.2,63.1 24.5,62.8 24.7,62.6 24.9,62.3 24.9,61.9 25,58.7 26.4,55.8 28.6,53.7 30.8,51.6 33.7,50.3 37,50.3 40.3,50.3 43.4,51.7 45.6,53.8 47.8,56 49.1,59 49.1,62.4L49.1,62.4C49.1,63.2 49.7,63.8 50.5,63.8 50.5,63.8 50.5,63.8 50.5,63.8 50.5,48.6 56.1,28.4 64,20.4 52.5,20.5 42.1,25.1 34.6,32.6z" />  
    70.                             <GeometryDrawing Brush="#FFE53839" Geometry="F0 M128,128z M0,0z M93.4,32.6C101,40.1,105.7,50.4,105.9,61.8L105.9,61.8C105.9,62.6 105.3,63.2 104.6,63.3 104.2,63.3 103.8,63.1 103.5,62.8 103.3,62.6 103.1,62.3 103.1,61.9 103,58.7 101.6,55.8 99.4,53.7 97.2,51.6 94.3,50.3 91,50.3 87.7,50.3 84.6,51.7 82.4,53.8 80.2,56 78.9,59 78.9,62.4L78.9,62.4C78.9,63.2 78.3,63.8 77.5,63.8 77.5,63.8 77.5,63.8 77.5,63.8 77.5,48.6 71.9,28.4 64,20.4 75.5,20.5 85.9,25.1 93.4,32.6z" />  
    71.                         </DrawingGroup>  
    72.                     </DrawingGroup>  
    73.                 </DrawingGroup>  
    74.             </DrawingImage.Drawing>  
    75.         </DrawingImage>   

    Please take a note that this code is nothing but images. Here I have used DrawingImage class to prepare images from SVG data.

    Step 2

    • To add button, we will use TaskbarItemInfo
    • Define TaskbarItemInfo for MainWindow.xaml as mentioned below
    1. <Window.TaskbarItemInfo>  
    2.      <TaskbarItemInfo>  
    4.      </TaskbarItemInfo>  
    5. </Window.TaskbarItemInfo>  

    Step 3

    With TaskbarItemInfo we can work with the below-mentioned features

    • Description
    • Overlay
    • ProgressState
    • ProgressValue
    • ThumbButtonInfos
    • ThumbnailClipMargin

    In this article we will use ThumbButtonInfos to add button.

    Step 4

    Declare Three ThumbButtonInfos under TaskbarItemInfo declared in the previous step as mentioned below.

    1. <ThumbButtonInfo Description="First Button" Click="ThumbButtonInfo1_Click" ImageSource="{StaticResource Rocket}"></ThumbButtonInfo>  
    2.                 <ThumbButtonInfo Description="Second Button" Click="ThumbButtonInfo2_Click" ImageSource="{StaticResource Boat}"></ThumbButtonInfo>  
    3.                 <ThumbButtonInfo Description="Third Button" Click="ThumbButtonInfo3_Click" ImageSource="{StaticResource Balloon}"></ThumbButtonInfo> 

    Here I have declared Click Events for all those buttons to show messagebox. And bound images declared in App.xaml resources.

    Complete code of MainWindow Xaml should looks like below.

    1. <Window x:Class="WpfWindowWithTaskBarButtons.MainWindow"  
    2.         xmlns=""  
    3.         xmlns:x=""  
    4.         xmlns:d=""  
    5.         xmlns:mc=""  
    6.         xmlns:local="clr-namespace:WpfWindowWithTaskBarButtons"  
    7.         mc:Ignorable="d"  
    8.         Title="MainWindow" Height="350" Width="525">  
    9.     <Window.TaskbarItemInfo>  
    10.         <TaskbarItemInfo>  
    11.             <TaskbarItemInfo.ThumbButtonInfos>  
    12.                 <ThumbButtonInfo Description="First Button" Click="ThumbButtonInfo1_Click" ImageSource="{StaticResource Rocket}"></ThumbButtonInfo>  
    13.                 <ThumbButtonInfo Description="Second Button" Click="ThumbButtonInfo2_Click" ImageSource="{StaticResource Boat}"></ThumbButtonInfo>  
    14.                 <ThumbButtonInfo Description="Third Button" Click="ThumbButtonInfo3_Click" ImageSource="{StaticResource Balloon}"></ThumbButtonInfo>  
    15.             </TaskbarItemInfo.ThumbButtonInfos>  
    16.         </TaskbarItemInfo>  
    17.     </Window.TaskbarItemInfo>  
    18.     <Grid>  
    20.     </Grid>  
    21. </Window>  

    Class File for MainWindow should look like below.

    1. public partial class MainWindow : Window  
    2.     {  
    3.         public MainWindow()  
    4.         {  
    5.             InitializeComponent();  
    6.         }  
    7.         private void ThumbButtonInfo1_Click(object sender, EventArgs e)  
    8.         {  
    9.             MessageBox.Show("First Button Clicked");  
    10.         }  
    11.         private void ThumbButtonInfo2_Click(object sender, EventArgs e)  
    12.         {  
    13.             MessageBox.Show("Second Button Clicked");  
    14.         }  
    15.         private void ThumbButtonInfo3_Click(object sender, EventArgs e)  
    16.         {  
    17.             MessageBox.Show("Third Button Clicked");  
    18.         }  
    19.     }  

    That’s it guys, we have added three buttons in Application toolbar preview window similar to WindowMedia Player.

    Run the application and have a look.



    Salı, 29 Mayıs 2018 / Published in Uncategorized

    ActionInvoker In ASP.NET MVC

    In this article we will be discussing how to invoke the action methods base of custom logic and how to redirect a request for an action method to another action method in the same controller or another controller.

    We can achieve this with the below two different ways,

    • Controller Action Invoker
    • Action Invoker

    Now  let’s discuss them briefly.

    Controller Action Invoker

    This invokes the specified action by using specific controller context. By implementing ControllerActionInvoker class and overriding InvokeAction action method you can achieve the same. InvokeAction is having controller context and action name as parameter and it returns the result of the executing action.

    Let’s see this with the below example.

    • Add folder Utilities
    • Now add class CustomControllerInvoker as shown below
    1. public class CustomControllerInvoker:ControllerActionInvoker  
    2.     {  
    3.         public override bool InvokeAction(ControllerContext controllerContext, string actionName)  
    4.         {  
    5.             if (actionName.Equals("Index"))  
    6.             {  
    7.                 ViewResult result = new ViewResult();  
    8.                 result.View = result.ViewEngineCollection.FindView(controllerContext, "About"null).View;  
    9.                 InvokeActionResult(controllerContext, result);  
    10.                 return true;  
    11.             }  
    12.             else  
    13.             {  
    14.                 return base.InvokeAction(controllerContext, actionName);  
    15.             }  
    18.         }  
    19.     }  

    Now, above, we have inherited ControllerActionInvoker in CustomControllerInvoker and have overridden InvokeAction. InvokeAction will check if incoming request is for Index action method then it will redirect it to About action method else it will execute called action method.

    Now assign CustomControllerInvoker, the invoker of Home controller.

    1. public  HomeController()  
    2.  {  
    3.       this.ActionInvoker = new CustomControllerInvoker();  
    5.  }  

    Action Invoker

    This invokes the specified action by using specific controller context. By implementing IActionInvoker interface and overriding InvokeAction action method you can achieve the same. InvokeAction has controller context and action name as parameter and it returns result of executing action.

    Let’s see this with the below example,

    Now add class CustomActionInvoker in Utilities folder as shown below.

    1. public class CustomActionInvoker : IActionInvoker  
    2.     {  
    3.         public bool InvokeAction(ControllerContext controllerContext, string actionName)  
    4.         {  
    5.             if (actionName.Equals("About", StringComparison.CurrentCultureIgnoreCase))  
    6.             {  
    7.                 controllerContext.HttpContext.Response.Write("This should be the home page");  
    8.                 return true;  
    9.             }  
    10.             else  
    11.             {  
    12.                 return false;  
    13.             }  
    14.         }  
    15.     }  

    Now, above, we have inherited IActionInvoker in CustomActionInvoker and have overridden InvokeAction. InvokeAction will check if incoming request is for About action method then it will show the message “This should be the home page."

    Now assign CustomActionInvoker the invoker of Home controller, as shown below.

    1. public  HomeController()  
    2.  {  
    3.       this.ActionInvoker = new CustomActionInvoker  
    4.  }  
    Salı, 29 Mayıs 2018 / Published in Uncategorized

    Build A Bluetooth Controlled Car Using Android Phone


    In this lesson, you will learn how to control an Android-controlled car using Bluetooth.

    Hardware requirements

    • The Arduino Uno
    • Bluetooth sensor
    • Motor driver
    • DC motor
    • Jumper wire
    • Chassis board

    Steps to follow,

    Step 1

    Connect the Arduino board to the laptop(or)computer.


    Step 2

    Installation of Arduino software on the laptop.


    Step 3

    Open the Arduino software in a computer.


    Step 4

    You can see main page of the Arduino software.


    Step 5

    Then open a new page in the software.

    select File→ New


    New page will open in the software.


    Step 6

    Then Click TOOL→ Select BOARD → then press ARDUINO/GENUINO UNO R3


    Set to the board Arduino Uno.

    Step 7

    Again Select TOOL → Select a PORT→ COM3 ARDUINO UNO


    Port set the COM3

    Step 8

    I have given a source code that you can use or you can use own source code

    Then select File → open → select written program →open the program


    You have to select a code which is on this folder.


    Select the program and open it.


    Source code

    I have given the program code.

    1. int motorLpin1 = 2;  
    2. int motorLpin2 = 3;  
    3. int motorRpin1 = 4;  
    4. int motorRpin2 = 5;  
    5. int motorLpwm = 10;  
    6. int motorRpwm = 11;  
    7. int motorSpeed = 125;  
    8. int turn = 45;  
    9. void setup() {  
    10.     Serial.begin(9600);  
    11.     Serial.flush();  
    12.     pinMode(motorLpin1, OUTPUT);  
    13.     pinMode(motorLpin2, OUTPUT);  
    14.     pinMode(motorRpin1, OUTPUT);  
    15.     pinMode(motorRpin2, OUTPUT);  
    16.     pinMode(motorLpwm, OUTPUT);  
    17.     pinMode(motorRpwm, OUTPUT);  
    18. }  
    19. void loop() {  
    20.     String input = "";  
    21.     while (Serial.available()) {  
    22.         input += (char);  
    23.         delay(5);  
    24.     }  
    25.     if (input == "n") {  
    26.         stp();  
    27.     } else if (input == "F") {  
    28.         fwd();  
    29.     } else if (input == "R") {  
    30.         rev();  
    31.     } else if (input.indexOf("TL") > -1) {  
    32.         lft();  
    33.     } else if (input.indexOf("TR") > -1) {  
    34.         rght();  
    35.     } else if (input != "") {  
    36.         motorSpeed = input.toInt();  
    37.     }  
    38. }  
    39. void fwd() {  
    40.     analogWrite(motorLpwm, motorSpeed);  
    41.     analogWrite(motorRpwm, motorSpeed);  
    42.     digitalWrite(motorLpin1, 1);  
    43.     digitalWrite(motorLpin2, 0);  
    44.     digitalWrite(motorRpin1, 1);  
    45.     digitalWrite(motorRpin2, 0);  
    46. }  
    47. void rev() {  
    48.     analogWrite(motorLpwm, motorSpeed);  
    49.     analogWrite(motorRpwm, motorSpeed);  
    50.     digitalWrite(motorLpin1, 0);  
    51.     digitalWrite(motorLpin2, 1);  
    52.     digitalWrite(motorRpin1, 0);  
    53.     digitalWrite(motorRpin2, 1);  
    54. }  
    55. void lft() {  
    56.     analogWrite(motorLpwm, motorSpeed – turn);  
    57.     analogWrite(motorRpwm, motorSpeed + turn);  
    58.     digitalWrite(motorLpin1, 0);  
    59.     digitalWrite(motorLpin2, 1);  
    60.     digitalWrite(motorRpin1, 1);  
    61.     digitalWrite(motorRpin2, 0);  
    62. }  
    63. void rght() {  
    64.     analogWrite(motorLpwm, motorSpeed + turn);  
    65.     analogWrite(motorRpwm, motorSpeed – turn);  
    66.     digitalWrite(motorLpin1, 1);  
    67.     digitalWrite(motorLpin2, 0);  
    68.     digitalWrite(motorRpin1, 0);  
    69.     digitalWrite(motorRpin2, 1);  
    70. }  
    71. void stp() {  
    72.     analogWrite(motorLpwm, 0);  
    73.     analogWrite(motorRpwm, 0);  
    74.     digitalWrite(motorLpin1, 1);  
    75.     digitalWrite(motorLpin2, 1);  
    76.     digitalWrite(motorRpin1, 1);  
    77.     digitalWrite(motorRpin2, 1);  
    78. }  

    Step 9

    Verify the program or compiler.


    Step 10

    Upload the code in the Arduino board.


    Step 11

    Then connect the hardware components as per the connection diagram given in the figure.


    Complete the connection as per the diagram.

    Step 12

    Install the Bluetooth control robot application using the Playstore on your android phone.


    Step 13

    Open the Bluetooth control application on your phone.


    Then select Bluetooth device in the application


    Connect the HC05 Bluetooth module with the Android phone application.[password=1234 (or) 0000 ,from bluetooth module]


    We can now operate the Arduino car using your android application.

    Step 14

    The Arduino car will be working successfully.


    Move the Arduino car to the right, left, forward, back and side using the Android application.

    Now you completely learned to control the Bluetooth Arduino car using your Android phone.


    The Arduino project using an Android Bluetooth application to control the Arduino Uno car by connecting to the Aluetooth has been created and executed.

    More exciting articles are coming up next.

    Salı, 29 Mayıs 2018 / Published in Uncategorized

    ASP.NET Core API Reference

    The following is a list of top level namespaces in the ASP.NET Core class library. Each namespace contains a set of functionally-related types.

    If you find an issue or an inconsistency, we would love to hear about it! Go to the ASP.NET Core docs repo on Github, and open an issue to let us know.

    Salı, 29 Mayıs 2018 / Published in Uncategorized

    ASP.NET Core 2.1.0-rc1 now available

    Today we’re happy to announce the first release candidate of ASP.NET Core 2.1! This release should be very close to the final stable release of ASP.NET Core 2.1 and includes primarily bug fixes and polish for the features that we shipped in earlier previews. This is a "go live" release that can be used in production with the understanding that you will need to update to the final stable release once it is available.

    Also, be sure to read about .NET Core 2.1.0-rc1 and Entity Framework Core 2.1.0-rc1.

    Get started

    To get started with ASP.NET Core 2.1.0-rc1 download the .NET Core 2.1.0-rc1 SDK

    Customers using Visual Studio should also install Visual Studio 2017 Update 7 or Visual Studio for Mac 7.5.

    Migrating an ASP.NET Core 2.0.x project to 2.1.0-rc1

    To migrate an existing ASP.NET Core 2.0.x project to 2.1.0-rc1:

    1. Open the project’s .csproj file and change the value of the <TargetFramework> element to netcoreapp2.1
      • Projects targeting .NET Framework rather than .NET Core, e.g. net471, don’t need to do this
    2. In the same file, update the versions of the various <PackageReference> elements for any Microsoft.AspNetCore, Microsoft.Extensions, and Microsoft.EntityFrameworkCore packages to 2.1.0-rc1-final
    3. In the same file, remove any references to <DotNetCliToolReference> elements for any Microsoft.AspNetCore, Microsoft.VisualStudio, and Microsoft.EntityFrameworkCore packages. These tools are now deprecated and are replaced by global tools.
    4. In the same file, remove the <DotNetCliToolReference> elements for any Microsoft.AspNetCore packages. These have been replaced by global tools.

    That should be enough to get the project building and running against 2.1.0-preview2. The following steps will change your project to use new code-based idioms that are recommended in 2.1

    1. Open the Program.cs file
    2. Rename the BuildWebHost method to CreateWebHostBuilder, change its return type to IWebHostBuilder, and remove the call to .Build() in its body
    3. Update the call in Main to call the renamed CreateWebHostBuilder method like so: CreateWebHostBuilder(args).Build().Run();
    4. Open the Startup.cs file
    5. In the ConfigureServices method, change the call to add MVC services to set the compatibility version to 2.1 like so: services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    6. In the Configure method, add a call to add the HSTS middleware after the exception handler middleware: app.UseHsts();
    7. Staying in the Configure method, add a call to add the HTTPS redirection middleware before the static files middleware: app.UseHttpsRedirection();
    8. Open the project property pages (right-mouse click on project in Visual Studio Solution Explorer and select “Properties”)
    9. Open the “Debug” tab and in the IIS Express profile, check the “Enable SSL” checkbox and save the changes
    10. In you project file change any package reference to Microsoft.AspNetCore.All package to Microsoft.AspNetCore.App and add additional packages as needed to restore the your required dependency graph

    Note that some projects might require more steps depending on the options selected when the project was created and modifications made to the project.

    Deploying to Azure

    Azure App Service will start deploying .NET Core 2.1.0-rc1 with the next week or so. In the meantime you can still deploy .NET Core 2.1.0-rc1 for your app as a site extension.

    New features and enhancements

    This release primarily contains refinements and bug fixes to the features we shipped in earlier previews, but there are a couple of new features and enhancements worth calling out. You can find a complete list of the features and enhancements in this release in the release notes.

    New Razor UI Class Library template

    The new Razor Class Library project template makes it easy to build reusable Razor UI class libraries. Razor class library projects are already setup with the Razor SDK to enable building Razor files (.cshtml) like MVC views and Razor Pages.

    To create a new Razor class library project from the command-line:

    dotnet new razorclasslib -o RazorClassLib1

    You can also create Razor class library projects in Visual Studio from the "New ASP.NET Core Web Application" dialog.

    Improvements to MVC test infrastructure

    You can now derive from WebApplicationFactory to create a custom factory that configures the HttpClient by overriding ConfigureClient. This enables testing scenarios that requrie specific HttpClient configuration, like adding specific HTTP headers.

    We also update the default environment setup by the WebApplicationFactory to be development to simplify scenarios like accessing user secrets and other development resources.

    SignalR updates

    • The MessagePack protocol library for SignalR was renamed to Microsoft.AspNetCore.SignalR.Protocols.MessagePack
    • The JavaScript/TypeScript client Hub connection API changed to use the HubConnectionBuilder (similar to the C# client)
    • Sticky sessions are now required when using the WebSockets transport unless the skipNegotiation flag is set to true:

      var connection = new signalR.HubConnectionBuilder()
        .withUrl("/chat", { skipNegotiation: true, transport: signalR.HttpTransportType.WebSockets })


    Thank you for trying out ASP.NET Core 2.1.0-rc1! Assuming everything goes smoothly with this release we should have a stable release of ASP.NET Core 2.1 shortly. If you have any questions or find any issues with this release please let us know by filing issues on GitHub.

    Salı, 29 Mayıs 2018 / Published in Uncategorized

    Learning WebRTC peer-to-peer communication, part 1

    [link VIDEO]

    Remember blockchain-redux? Yeah, I’m still working on it. Last time, we got it to share blocks between clients in real-time.

    But that still used Firebase as the communication channel. Our blockchain isn’t really distributed. ☹️

    I have to fix that before my talk at WeAreDevelopers Congress in Vienna. Otherwise, what’s the point?

    WebRTC can do that for us. Get browsers to talk to each other without any servers at all.

    I built a demo app that uses RTCPeerConnection to build a peer-to-peer connection with itself. You can see the code on GitHub or keep reading.

    Got same page WebRTC working o/

    Now how do I peer-to-peer

    — Swizec (@Swizec) May 6, 2018

    Since iOS 11, WebRTC now works in all browsers people use. You can use it for real!

    Try my demo here. I’d embed an iframe, but browser security rules say no.

    WebRTC offers 3 APIs:

    In this article, we’ll use 2 of them. Media and peer connection.

    RTCPeerConnection connects clients without servers

    RTCPeerConnection process sketch

    RTCPeerConnection process sketch

    You establish a connection between 2 clients on the same page like this

    1. Instantiate two RTCPeerConnection objects
    2. Add each other as ICE candidates
    3. createOffer on the 1st object
    4. set local/remote “description” on both
    5. createAnswer on the 2nd object
    6. set remote/local “description” on both
    7. Enjoy your direct communication

    Here’s how that goes in code.

    We start with a React component that renders 2 videos and 3 buttons. It has a bunch of default state that we’ll use to drive everything.

    class WebRTCPeerConnection extends React.Component {
        state = {
            startDisabled: false,
            callDisabled: true,
            hangUpDisabled: true,
            servers: null,
            pc1: null,
            pc2: null,
            localStream: null
        localVideoRef = React.createRef();
        remoteVideoRef = React.createRef();
        start = () => {
            // start media devices
        call = () => {
            // initiate a call
        hangUp = () => {
            // hang up connection
        render() {
            const { startDisabled, callDisabled, hangUpDisabled } = this.state;
            return (

    class WebRTCPeerConnection extends React.Component { state = { startDisabled: false, callDisabled: true, hangUpDisabled: true, servers: null, pc1: null, pc2: null, localStream: null }; localVideoRef = React.createRef(); remoteVideoRef = React.createRef(); start = () => { // start media devices }; call = () => { // initiate a call }; hangUp = () => { // hang up connection }; render() { const { startDisabled, callDisabled, hangUpDisabled } = this.state; return (

    Salı, 29 Mayıs 2018 / Published in Uncategorized

    Time for another blog series! This time we will focus on the new C# 7.2 language features for which we’ve added support in ReSharper 2018.1 and Rider 2018.1. We will see how they help to improve our code quality and how they work under the hood.

    In this series: (we will update the table of contents as we progress)

    Let’s get started with something easy …

    Leading digit separators in numeric literals

    Beginning with C# 7.0, we can use underscores to separate large numeric literals into chunks of digits – thus called digit separators. Using digit separators can help to improve readability in our code base:

    // before C# 7.0

    var a = 1000000000;

    var b = 0x001111000011;


    // with C# 7.0

    var c = 1_000_000_000;

    var d = 0x0011_1100_0011;

    Prior to C# 7.2, digit separators were only permitted after the first significant digit of a hexadecimal or binary literal. This limitation has been removed so that we can now use the first group solely to specify the base (or radix) of our numeric literal. Other limitations from C# 7.0 remain the same, including that underscores cannot occur next to the decimal, next to the exponent character or next to the type specifier.

    // became valid with C# 7.2

    var a = 0b_1_1_0;

    var b = 0x_ff_ff_00;


    // still invalid

    var c = 10_.0;  // error: next to decimal

    var d = 1.1e_1; // error: next to exponent character

    var e = 10_f;   // error: next to type specified

    Speaking of numeric literals, we hope you didn’t miss our several new context actions for converting between different bases and adding/removing digit separators:

    Ref structs

    In order to understand ref structs, we first have to understand the concept of value types. Structs, like bool, int or char, are value types. They are a more or less a cut-down version of classes, which doesn’t allow inheritance (though they implicitly derive from System.ValueType) or finalizers. Also, a variable of value type cannot be assigned as null (we have to use nullable types for that).

    When passing a local variable with value type to another method, in reality a copy of this value is passed; so called by-value. This is the opposite of the by-reference approach, where changes in the called method will also be reflected in the call-site:

    void M()


        var i = 5;

        N(ref i);

        Console.WriteLine(i); // Outputs 10



    void N(ref int i)


        i = 10;


    Another characteristic of value types is that they are accessed directly (instead of via pointers) and that they’ll be usually allocated on the stack. This behavior can greatly improve our performance. However, there are cases in which values types can be allocated on the managed heap: whenever we box a value type (e.g. to object or an interface type) or when we declare them as a static or instance member in a reference type. As a result, we might not gain the performance benefit we’ve expected.

    Note: we can use the Heap Allocation Viewer plugin, to find out about various allocations. This plugin is also available for Rider.

    Luckily, ref structs can help in high performance scenarios. A ref struct looks like a normal struct, but with a ref modifier in front of it. When used, the compiler will produce an error for any operation that would expose the object to the heap (for older compilers, it generates an ObsoleteAttribute on object base classes, like GetHashCode or ToString). Think of it as a stack-only struct:

    Ref structs can also be readonly structs, which we will look at a little later.

    In parameters

    We’ve already seen how value types can be passed by-reference, and how this can change the value on call-site. While reducing the amount of allocations, we are also exposing ourselves to possible mutations of our local. There is no guarantee that it will keep the initial value we’ve assigned. ReSharper has always notified about this potential issue (and reassignments in general) by highlighting the local in bold (need to enable Options | Highlight Identifiers in Options | Inspection Settings):

    Fortunately, C# 7.2 introduces so-called in parameters. We can think of them as readonly ref parameters, which allow to gain all performance improvements while at the same time ensuring that the method (and sub calls) cannot modify the parameter:

    public void M(in int number)


        number = 5; // error!


    As described, the parameter becomes immutable within the declaring method. However, it can still be changed from the outside, for instance when working with several threads. Effectively, the value of an in parameter can still change between multiple accesses.

    It also worth to notice that we can pass parameters with or without the in modifier. However, adding it will enforce our expectation on call-site and prevent changing semantics. The in modifier is also part of the method signature and therefore influences overload resolution:

    There are also cases where in parameters cannot be used: entry point declarations (static void Main), async methods and iterator methods.

    Using in parameters can be quite helpful. However, there is one remaining issue with them that we will examine in the next post. Stay tuned!

    Download ReSharper 2018.1 now! Or give Rider 2018.1 a try. We’d love to hear your feedback!

    Salı, 29 Mayıs 2018 / Published in Uncategorized

    Carl Franklin

    Carl Franklin is Executive Vice President of App vNext, a software development firm focused on the latest methodologies and technologies. Carl is a 20+ year veteran of the software industry, co-host and founder of .NET Rocks!, the first and most widely listened to podcast for .NET developers, a Microsoft MVP for Kinect for Windows, a Microsoft Regional Director, and Senior Executive of Pwop Studios, a full-service audio and video production/post production studio located in Southeastern Connecticut.

    He was awarded the MVP for Kinect because of his work on gesture recognition. Namely, KinectTools and GesturePak. KinectTools is an abstraction over the Kinect 2.0 SDK that takes the detail work out of using the Kinect in a Windows application. GesturePak lets you record, edit, and recognize gestures in a Windows application. Both are free open source products.

    Carl is also the creator of Music to Code By, a set of 25-minute long instrumental music pieces designed to get you into a state of flow and keep you there. Music to Code By has been praised widely by developers for keeping them focused and helping them solve difficult problems.

    Carl has been a leader in the .NET community since 2002, and in the Visual Basic (VB) community before that. In the very early days he wrote for Visual Basic Programmer’s Journal, authoring the Q&A column of that magazine as well as many feature articles for VBPJ and other magazines. He has authored two books for John Wiley & Sons on sockets programming in VB, and in 1994 he helped create the very first web site for VB developers, Carl & Gary’s VB Home Page.

    Before he started .NET Rocks! in 2002 (three years before the word ‘podcast’ became popular) he developed and taught hands-on training classes for VB.NET and ASP.NET via his training company, Franklins.Net.

    Carl has spoken regularly at conferences around the world, such as DevIntersection, NDC, NDC London, OreDev, Microsoft TechEd, Microsoft TechEd Europe, DevTeach, DevReach, and others.

    In addition to his work in the development field, Carl works in the music business as a composer, recording engineer, producer, multi-instrumentalist, and vocalist. With his band, the Franklin Brothers, he has produced two albums, Lifeboat to Nowhere and Been a While. Both albums get nothing but five star reviews. Noted guitar virtuoso John Scofield has collaborated with Carl on two songs, Chain Reaction and Groove or Get Out of the Way.

    Richard Campbell

    Richard Campbell started playing with microcomputers in 1977 at the age of 10. He’s really never done anything else since. In that time he’s been involved in every level of the PC industry, from manufacturing, to sales, to development, and into large scale infrastructure implementation. He has been a witness and participant to the Bill Gates vision of "A PC on every desktop."

    For years he’s served as a consultant to companies in many countries, including Barnes&, Dow Chemical, Johnson & Johnson Health Care Services, Reuters, Subaru/Isuzu and the U.S. Air Force, providing advice on architecture, scaling systems and mentoring development teams. His long experience in working with large scale systems made him a sought-after consultant during the halycon years of the DotCom boom. He worked closely with venture capital and private equity firms providing architectural guidance and due diligence.

    He is a Microsoft Regional Director and is recognized as a Microsoft Most Valuable Professional (MVP) in the area ofASP.NET development.

    In 2004 Richard first met Carl Franklin, creator of .NET Rocks (, The Internet Audio Talkshow for .NET Developers. Richard was a guest on show 69, but his friendship with Carl quickly evolved into a partnership and by show 100 in early 2005 he came onboard as co-host. In 2007 he started RunAs Radio (, a podcast for IT Professionals.

    He is a co-founder of Strangeloop Networks, which was acquired by Radware in 2013 and spent five years on the board of directors of Telerik which was acquired by Progress Software in 2014.

    In 2012 Richard founded the Humanitarian Toolbox (, an organization designed to let developers around the world donate their skills to disaster relief organizations by building open source software. By 2014, Humanitarian Toolbox became a 501(c)3 registered US charity, working on a number of different projects for the United Nations, US Center for Disease Control and Red Cross.

    Today Richard is a consultant and advisor to a number of successful technology firms as well as the co-owner and content planner of the DevIntersection ( group of conferences.

    Salı, 29 Mayıs 2018 / Published in Uncategorized

    Today, we’re announcing .NET Core 2.1 Release Candidate 1 (RC 1). The .NET Core 2.1 RC 1 is now ready for broad testing and for production use. Our quality, reliability, and performance testing give us confidence that the release is ready for the first set of production users. On the metrics that we can measure, .NET Core 2.1 is a large step forward from .NET Core 2.0.

    ASP.NET Core 2.1 RC 1 and Entity Framework 2.1 RC 1 are also releasing today.

    You can download and get started with .NET Core 2.1 RC 1, on Windows, macOS, and Linux:

    You can see complete details of the release in the .NET Core 2.1 RC 1 release notes. Related instructions, known issues, and workarounds are included in releases notes. Please report any issues you find in the comments or at dotnet/core #1506

    You can develop .NET Core 2.1 apps with Visual Studio 2017 15.7, Visual Studio for Mac 7.5, or Visual Studio Code.

    At this point in the release, the feature set and performance characteristics are not changing much. Look at Announcing .NET Core 2.1 Preview 2 and Performance Improvements in .NET Core 2.1 to learn about improvements in the release that are not covered in this post.

    “Go Live” Support

    NET Core 2.1 RC is supported by Microsoft and can be used in production. As always, we recommend that you test your app before deploying to production. If anything seems strange, don’t deploy! If all of your tests pass with .NET Core 2.1 RC and you are enthusiastic to start using the 2.1 benefits, then go ahead and deploy. Tell us about your experiences.

    Another option is to adopt the .NET Core 2.1 RC SDK while continuing to target earlier .NET Core releases, like 2.0. We believe that many people do this.

    Alpine Support

    Alpine Linux is a very small and security-focused Linux distro. It’s also quickly becoming the favored base image for Docker. We added support for it as a preview in 2.0 after many requests for it. Since then, the requests for it have only increased.

    We are adding official support for Alpine starting with this RC release. We intend to switch to Alpine 3.8 as the version we test on and support as soon as Alpine 3.8 releases (guess: June 2018).

    If you want to use .NET Core and Alpine with Docker, use the following tags:

    • 2.1-sdk-alpine
    • 2.1-runtime-alpine

    If you are using the 2.0 Alpine images at microsoft/dotnet, switch to 2.1. We will not update the 2.0 Alpine images much longer, given that they remain in preview.

    The runtime ID for Alpine was previously alpine-3.6. There is a now a more generic runtime ID for Alpine and similar distros, called linux-musl, to support any Linux distro that uses musl libc. All of the other runtime IDs assume glibc.

    ARM Support

    We’ve had many requests for ARM, particularly for running on the Raspberry Pi. .NET Core is now supported on Linux ARM32 distros, like Raspbian and Ubuntu. The same download links at the start of the post provide ARM downloads, too.

    Note: .NET Core 2.1 is supported on Raspberry Pi 2+. It isn’t supported on the Pi Zero or other devices that use an ARMv6 chip. .NET Core requires ARMv7 or ARMv8 chips, like the ARM Cortex-A53.

    If you want to use .NET Core on ARM32 with Docker, you can use any of the following tags:

    • 2.1-sdk
    • 2.1-runtime
    • 2.1-aspnetcore-runtime
    • 2.1-sdk-stretch-slim-arm32v7
    • 2.1-runtime-stretch-slim-arm32v7
    • 2.1-aspnetcore-runtime-stretch-slim-arm32v7
    • 2.1-sdk-bionic-arm32v7
    • 2.1-runtime-bionic-arm32v7
    • 2.1-aspnetcore-runtime-bionic-arm32v7

    Note: The first three tags are multi-arch.

    If you are using the 2.0 ARM32 images at microsoft/dotnet, switch to 2.1. We will not update the 2.0 ARM32 images much longer, given that they remain in preview.

    Our friends on the Azure IoT Edge team use the .NET Core Bionic ARM32 Docker images to support developers writing C# with Edge devices.

    If you are new to Raspberry Pi, I suggest the awesome Pi resources at AdaFruit. You can buy a Pi there, too.

    We are hearing requests for ARM64. We are working on it. For now, our best recommendation is to use our ARM32 build on ARM64. Many ARM64 chips (AKA “ARMv8”) support ARM32 instructions (AKA “ARMv7”). Raspberry Pi 3+ devices have such a chip. I installed an experimental version of ARM64 Debian on a Pi 3 for this purpose. It works. We’ll update you when our ARM64 support improves.

    Major thanks to Samsung and Qualcomm for investing heavily on .NET Core ARM32 and ARM64 implementations. Please thank them, too! These contributions speak to the value of open-source.

    Docker Images

    .NET Core and ASP.NET Core images have been updated for .NET Core 2.1 RC at microsoft/dotnet. The samples repo has also been updated for 2.1 RC.

    You can quickly try .NET Core 2.1 RC with one of our pre-built sample images:

    Console app:

    docker pull microsoft/dotnet-samples:dotnetapp
    docker run --rm microsoft/dotnet-samples:dotnetapp

    ASP.NET Core app

    docker pull microsoft/dotnet-samples:aspnetapp
    docker run --rm -it -p 8000:80 --name aspnetcore_sample microsoft/dotnet-samples:aspnetapp

    You can view the site at http://localhost:8000 on most machines. If that doesn’t work check out View ASP.NET Core app in a running container on Windows.

    Brotli Compression

    Brotli is a general-purpose lossless compression algorithm that compresses data comparable to the best currently available general-purpose compression methods. It is similar in speed to deflate but offers more dense compression. The specification of the Brotli Compressed Data Format is defined in RFC 7932. The Brotli encoding is supported by most web browsers, major web servers, and some CDNs (Content Delivery Networks). The .NET Core Brotli implementation is based around the c code provided by Google at google/brotli. Thanks, Google!

    Brotli support has been added to .NET Core 2.1. Operations may be completed using either the stream-based BrotliStream or the high-performance span-based BrotliEncoder/BrotliDecoder classes. You can see it used in the following example.

    The BrotliStream behavior is the same as that of DeflateStream or GZipStream to allow easily converting DeflateStream/GZipStream code to use BrotliStream.

    New Cryptography APIs

    The following enhancements have been made to .NET Core cryptography APIs:

    • New SignedCms APIsSystem.Security.Cryptography.Pkcs.SignedCms is now available in the System.Security.Cryptography.Pkcs package. The .NET Core implementation is available to all .NET Core platforms and has parity with the class from .NET Framework. See: dotnet/corefx #14197.
    • New X509Certificate.GetCertHash overload for SHA-2 — New overloads for X509Certificate.GetCertHash and X509Certificate.GetCertHashString accept a hash algorithm identifier to enable callers to get certificate thumbprint values using algorithms other than SHA-1. dotnet/corefx #16493.
    • New Span<T>-based cryptography APIs — Span-based APIs are available for hashing, HMAC, (cryptographic) random number generation, asymmetric signature generation, asymmetric signature processing, and RSA encryption.
    • Rfc2898DeriveBytes performance improvements — The implementation of Rfc2898DeriveBytes (PBKDF2) is about 15% faster, based on using Span<T>-based. Users who benchmarked an iteration count for an amount of server time may want to update iteration count accordingly.
    • Added CryptographicOperations classCryptographicOperations.FixedTimeEquals takes a fixed amount of time to return for any two inputs of the same length, making it suitable for use in cryptographic verification to avoid contributing to timing side-channel information. CryptographicOperations.ZeroMemory is a memory clearing routine that cannot be optimized away via a write-without-subsequent-read optimization.
    • Added static RandomNumberGenerator.Fill — The static RandomNumberGenerator.Fill will fill a Span with random values using the system-preferred CSPRNG, and does not require the caller to manage the lifetime of an IDisposable resource.
    • Added support for RFC 3161 cryptographic timestamps — New API to request, read, validate, and create TimestampToken values as defined by RFC 3161.
    • Add Unix EnvelopedCms — The EnvelopedCms class has been added for Linux and macOS.
    • Added ECDiffieHellman — Elliptic-Curve Diffie-Hellman (ECDH) is now available on .NET Core via the ECDiffieHellman class family with the same surface area as .NET Framework 4.7.
    • Added RSA-OAEP-SHA2 and RSA-PSS to Unix platforms — Starting with .NET Core 2.1 the instance provided by RSA.Create() can always encrypt or decrypt with OAEP using a SHA-2 digest, as well as generate or validate signatures using RSA-PSS

    .NET Core Global Tools

    The .NET Core global tools feature has stabilized. The syntax that was updated in Preview 2 hasn’t changed. You can try a pre-built global tool with the following example:

    dotnet tool install -g dotnetsay

    For global tool users, we recommend that you uninstall global tools that you installed with previous releases or just delete the .dotnet/tools and dotnet/toolspkgs directories in your user profile. The layout of the directory has changed, requiring tools to be reinstalled.

    For folks that built and published tools for .NET Core Preview 1 or Preview 2, you need to rebuild and republish them with .NET Core 2.1 RC. You will need to do the same thing when we publish RTM. .NET Core applications, including tools, do not roll-forward across preview versions.

    Note that .NET Core Global tools must target netcoreapp2.1. See the .NET Core 2.1 RC 1 release notes for more information on Global Tools updates.


    SourceLink is a system that enables a source debugging experiences for binaries that you either distribute or consume. It requires producers of SourceLink information and debuggers that support it. The Visual Studio debugger already supports SourceLink, starting with Visual Studio 2017 15.3. We have added support for generating SourceLink information in symbols, binaries, and NuGet packages in the .NET Core 2.1 RC SDK.

    You can start producing SourceLink information by following the example at dotnet/sourcelink.

    Our goal for the project is to enable anyone building NuGet libraries to provide source debugging for their users with almost no effort. There are a few steps left to enable the full experience, but you can get started now.

    The following screenshot demonstrates debugging a NuGet package referenced by an application, with source automatically downloaded from GitHub and used by Visual Studio 2017.

    Tiered Compilation

    We’ve added a preview of a new and exciting capability to the runtime called tiered compilation. It’s a way for the runtime to more adaptively use the Just-In-Time (JIT) compiler to get better performance.

    The basic challenge for JIT compilers is that compilation time is part of the application’s execution time. Producing better code usually means spending more time optimizing it. But if a given piece of code only executes once or just a few times, the compiler might spend more time optimizing it than the application would spend just running an unoptimized version.

    With tiered compilation, the compiler first generates code as quickly as possible, with only minimal optimizations (first tier). Then, when it detects that certain methods are executed a lot, it produces a more optimized version of those methods (second tier) that are then used instead. The second tier compilation is performed in parallel, which removes the tension between fast compile speeds and producing optimal code. This model can be more generically called Adaptive optimization.

    Tiered compilation is also beneficial for long-running applications, such as web servers. We’ll go into more detail in follow-on posts, but the short version is that the JIT can produce much better code than is in the pre-compiled assemblies we ship for .NET Core itself. This is mostly due to the fragile binary interface problem. With tiered compilation, the JIT can use the pre-compiled code it finds for .NET Core and then JIT-compile better code for methods that get called a lot. We’ve seen this scenario having a large impact for the tests in our performance lab.

    You can test tiered compilation with your .NET Core 2.1 RC application by setting an environment variable:


    In the final version of .NET Core 2.1, you will be able to opt in with the System.Runtime.TieredCompilation app-context switch. We aim to make tiered compilation the default in the future after we’ve had a chance to gather feedback and make any necessary improvements. We will publish more details about this new feature shortly.


    .NET Core 2.1 RC 1 is our third release on the way to the final version of 2.1. The quality is high enough now that we’re happy for you to start using .NET Core 2.1 in production. We’re heard a lot of positive feedback so far from folks who have tried out the RC. We hope you have the same experience. Please share your experience with us.

    We’re now very close to being done with the 2.1 release. We expect to ship the final version of 2.1 in the first half of 2018. Thanks to everyone that has helped along the way.