Design, Source and Split tabs are missing in Visual Studio 2015?

If the HTML file is in Solution Explorer, then right-click and select “Open With”. Otherwise open it with Open File dialog, but click the small dropdown arrow in the Open button, then select “Open With”. Then select “HTML (Web Forms) Editor with Encoding”. Then you should see the Design, Split and Source buttons. Click Design.


ASP.NET: The data protection operation was unsuccessful

the data protection operation was unsuccessful. this may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.

If you receive this error from one of your application, you resolve the problem in this way:

  1. Open IIS Manager
  2. Select Applications Pools, and go ahead and select the App Pool used by your app
  3. Right-click on it, and select Advanced Settings, Go to the Process Model Section and Find the “Load User Profile” Option and set it to True


Visual Studio 2015: upgrade all NuGet packages at one time


Open the Package Manager Console and use the Update-Package cmd-let to update all packages.

If this doesn't work, you have other two solution. Always in Package Manager Console you type one of those:

First solution
  1. $list = Get-package -project {Add project name here} for($i=0; $i -lt $list.Length;$i ++ ) { Update-Package -project {Add project name here} $list[$i].Id }

Replace {Add project name here} with your project name without braket

Second solution
  1. foreach ($p in get-project -all) { update-package -ProjectName $p.ProjectName }


Happy coding!

How to truncate log file in SQL Server

In SQL Server data is stored using two physical files:

  1. (.mdf) extension which contains the data.
  2. (.ldf) extension which contains log.

Log file size increases very rapidly and depend on the operation performed on the data. After a long time period this file becomes too large. When log file is too large it takes time to perform some operations like (attach, de-attach, backup, restore... etc ).

Step 1. Copy/type the below given SQL.

Step 2. Change @DBName to <Database Name>, @DBName_log to <Log File Name>

Step 3. Execute the SQL.


UWA: This application can only run in the context of an AppContainer

  1. Run it from VS (with or without debugging). This will actually install unpackaged version of your app, so you will see it in the start screen.
  2. Create a package to use locally. You can do this in VS by going to Store → Create App Package → Build a package to use only locally. This will create a bunch of files, including a command-line script that will actually install the app. You probably could use this method to distribute the app, but it would work only on developer-enabled computers.
  3. Publish your app to the Store. This is the only way you should use to distribute the apps to ordinary users.

C# Console Progress Bar

At work, I sometimes find myself needing to make Console applications which take some time. For example, I have a few console applications which parse dump files into objects and then insert the data into a database. Usually, I represent the progress of these applications with a simple incremental percentage display, however I thought I'd create a generic method which would display an ASCII progress bar.


At work, I sometimes find myself needing to make Console applications which take some time. For example, I have a few console applications which parse dump files into objects and then insert the data into a database. Usually, I represent the progress of these applications with a simple incremental percentage display, however I thought I'd create a generic method which would display an ASCII progress bar.

ProgressBar Class
  1. using System;
  2. using System.Text;
  3. using System.Threading;
  5. namespace ConsoleApplication1
  6. {
  7.     /// <summary>
  8.     /// An ASCII progress bar
  9.     /// </summary>
  10.     public class ProgressBar : IDisposable, IProgress<double>
  11.     {
  12.         private const int blockCount = 10;
  13.         private readonly TimeSpan animationInterval = TimeSpan.FromSeconds(1.0 / 8);
  14.         private const string animation = @"|/-\";
  15.         private bool showProgressBar = true;
  17.         private readonly Timer timer;
  19.         private double currentProgress = 0;
  20.         private string currentText = string.Empty;
  21.         private bool disposed = false;
  22.         private int animationIndex = 0;
  24.         public ProgressBar(bool ShowProgressBar = true)
  25.         {
  26.             showProgressBar = ShowProgressBar;
  27.             timer = new Timer(TimerHandler);
  29.             // A progress bar is only for temporary display in a console window.
  30.             // If the console output is redirected to a file, draw nothing.
  31.             // Otherwise, we'll end up with a lot of garbage in the target file.
  32.             if (!Console.IsOutputRedirected)
  33.             {
  34.                 ResetTimer();
  35.             }
  36.         }
  38.         public void Report(double value)
  39.         {
  40.             // Make sure value is in [0..1] range
  41.             value = Math.Max(0, Math.Min(1, value));
  42.             Interlocked.Exchange(ref currentProgress, value);
  43.         }
  45.         private void TimerHandler(object state)
  46.         {
  47.             lock (timer)
  48.             {
  49.                 if (disposed) return;
  51.                 string text = "";
  52.                 if (showProgressBar)
  53.                 {
  54.                     int progressBlockCount = (int)(currentProgress * blockCount);
  55.                     int percent = (int)(currentProgress * 100);
  56.                     text = string.Format("[{0}{1}] {2,3}% {3}",
  57.                            new string('#', progressBlockCount), new string('-', blockCount - progressBlockCount),
  58.                            percent,
  59.                            animation[animationIndex++ % animation.Length]);
  60.                 }
  61.                 else
  62.                 {
  63.                     text = animation[animationIndex++ % animation.Length].ToString();
  64.                 }
  65.                 UpdateText(text);
  67.                 ResetTimer();
  68.             }
  69.         }
  71.         private void UpdateText(string text)
  72.         {
  73.             // Get length of common portion
  74.             int commonPrefixLength = 0;
  75.             int commonLength = Math.Min(currentText.Length, text.Length);
  76.             while (commonPrefixLength < commonLength && text[commonPrefixLength] == currentText[commonPrefixLength])
  77.             {
  78.                 commonPrefixLength++;
  79.             }
  81.             // Backtrack to the first differing character
  82.             StringBuilder outputBuilder = new StringBuilder();
  83.             outputBuilder.Append('\b', currentText.Length - commonPrefixLength);
  85.             // Output new suffix
  86.             outputBuilder.Append(text.Substring(commonPrefixLength));
  88.             // If the new text is shorter than the old one: delete overlapping characters
  89.             int overlapCount = currentText.Length - text.Length;
  90.             if (overlapCount > 0)
  91.             {
  92.                 outputBuilder.Append(' ', overlapCount);
  93.                 outputBuilder.Append('\b', overlapCount);
  94.             }
  96.             Console.Write(outputBuilder);
  97.             currentText = text;
  98.         }
  100.         private void ResetTimer()
  101.         {
  102.             timer.Change(animationInterval, TimeSpan.FromMilliseconds(-1));
  103.         }
  105.         public void Dispose()
  106.         {
  107.             lock (timer)
  108.             {
  109.                 disposed = true;
  110.                 UpdateText(string.Empty);
  111.             }
  112.         }
  113.     }
  114. }


  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  8. namespace ConsoleApplication1
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Console.Write("Performing some task... ");
  15.             using (var progress = new ProgressBar())
  16.             {
  17.                 for (int i = 0; i <= 1000; i++)
  18.                 {
  19.                     progress.Report((double)i / 100);
  20.                     Thread.Sleep(20);
  21.                 }
  22.             }
  23.             Console.WriteLine("Done.");
  24.         }
  25.     }
  26. }

The code itself is pretty self explanatory and probably more verbose than it really needs to be, but it gets the job done and looks good.

Universal Windows app samples

On GitHub Microsoft have published a lot of examples for Universal Apps: the link is

This repo contains the samples that demonstrate the API usage patterns for the Universal Windows Platform (UWP) in the Windows Software Development Kit (SDK) for Windows 10. These code samples were created with the Universal Windows templates available in Visual Studio, and are designed to run on desktop, mobile, and future devices that support the Universal Windows Platform.

Universal Windows Platform development

These samples require Visual Studio 2015 and the Windows Software Development Kit (SDK) for Windows 10 to build, test, and deploy your Universal Windows apps.

Get a free copy of Visual Studio 2015 Community Edition with support for building Universal Windows apps

Additionally, to stay on top of the latest updates to Windows and the development tools, become a Windows Insider by joining the Windows Insider Program.

Become a Windows Insider

Using the samples

The easiest way to use these samples without using Git is to download the zip file containing the current version (using the link below or by clicking the "Download ZIP" button on the repo page). You can then unzip the samples and use them in Visual Studio 2015.

Download the samples ZIP

The samples use Linked files in Visual Studio to reduce duplication of common files, including sample template files and image assets. These common files are stored in the SharedContent folder at the root of the repository and referred to in the project files using links.

For more info about the programming models, platforms, languages, and APIs demonstrated in these samples, please refer to the guidance, tutorials, and reference topics provided in the Windows 10 documentation available in the Windows Developer Center. These samples are provided as-is in order to indicate or demonstrate the functionality of the programming models and feature APIs for Windows.

Error : DEP3321 – Can’t deploy to Windows 10 Mobile

With Windows 10 being rolled out as I write this article, there will be updated sample Windows Platform apps available soon (today). It’s also time to update your projects.

However, you may find yourself not able to deploy to Windows 10 Mobile after updating your projects or older samples to Windows 10 (build 10240). This post will show you how to resolve this problem.

The problem

You’ll see an error something like this when deploying to a physical Windows 10 Mobile device:

Error : DEP3321 : To deploy this application, your deployment target should be running Windows Universal Runtime version 10.0.10240.0 or higher. You currently are running version 10.0.10166.0. Please update your OS, or change your deployment target to a device with the appropriate version.

The error is pretty clear but how do we fix it? The resolution is with the MinTargetVersion setting.

The fix

We need to drop the lowest version your app targets to the version that your device has running, we can do this in one of two ways; through the project properties UI editor or manually edit the XML of the csproj file. I will show you how to do it manually because in some cases, the UI’s MinTarget dropdown list won’t show the lowest SDK if you do not have it installed. Below are the steps to fix it.

NOTE: Skip to step 3 if your project is already unloaded (it will show (unavailable) next to the name)

1) Right click on your project in Visual Studio

2) Select “Unload Project“, it will now appears as ProjectName (unavailable)

3) Right click on the unloaded project and select “Edit projectName.csproj

4) Locate the <TargetPlatformVersion> and <TargetPlatformMinVersion> items in the first <PropertyGroup>.

Here’s the “Before” screenshot:


5) Change the TargetPlatformMinVersion to the version that the error stated you are running. In this case, it’s 10166. Here’s the “After” screenshot:


6) Now Save and Close the file

7) Right click on the project again and select “Reload Project

8) Rebuild the project and deploy to device. Now you should be up and running!

Windows 10: Changing Paradigms

windows10-evolutionWindows 10 is the main discussion topic in the online development communities. This new operating system that is currently in the technical preview (and available through the Microsoft insider program) is a milestone in the platform unification journey that Microsoft embarked upon with starting with Windows Phone and Windows 8 operating systems. With Windows 10, developers and users are introduced to one development kit, one store, one application and one binary distribution package.

Introducing Windows Core

With Windows 10, developers are introduced to the new Windows Core concept. Windows Core is the refactored common core of Windows. It is the common set of APIs, a common infrastructure, which gives a, for the first time, truly binary compatibility across different platforms.

Up until Windows 10, a lot of the operating systems shared lots of commonality. In essence, most features were re-written from scratch for different platforms by separate development teams. Windows 8 was the first attempt to create a unified core with the so-called windows 8 kernel. The Windows CE kernel that was used for Windows Phone 7 was finally replaced with the Windows 8 kernel on Windows Phone 8. Xbox platform with the same kernel joined the unified platform with the release of Xbox One.

However, even though the kernels were the same, the implementation still differed on certain features which led to the Universal App Concept. The core functionality for mobile and desktop apps were implemented in either shared libraries or windows runtime class libraries targeting certain platforms that could be reused on the separate binaries for the respective platforms.

Universal App Platform

Universal App Platform is another new concept that we, developers, will need to get acquainted with. UAP is a collection of contracts and versions. It defines the platform that is running your application and acts as a broker between the application and the operating systems. It is built on top of the Windows Core and can be described as a superset of all the APIs that are supported on different devices and platforms running Windows 10.

With this new concept, the developers’ responsibility towards the OS shifts towards the UAP and in return the operating system is responsible for providing the UAP to the applications. Targeting platforms with the UAP is as simple as a manifest declaration.

<TargetPlaform Name="Microsoft.Universal" minVersion="" maxVersionTested="" />

The existence of a broker between the application and the operating system also creates an OS-agnostic development experience. For instance, if/when a new version of the OS becomes available, the application does not need to be aware of the version of the OS. Only important thing is to check if the UAP version is compatible with the current application.

Extensions SDK

Extensions SDK is really what makes the device specific APIs accessible. In an object oriented analogy, if the UAP is defining the abstract classes and interfaces to all the available APIs, the extensions SDK provides the implementations for these device specific feature sets. For instance, without adding the windows phone extension SDK as a reference to your application (the extension SDKs can be added using the Add Reference link in the project menu), the UAP will not be able to provide your application the access to types like BackButtonPressed or a contract like Wallet.

API Information Metadata

Since your application communicates with the OS through the UAP, and using the implementation by the extension sdks, the easiest way to probe for a certain API or device is the foundation metadata namespace. ApiInformation static class lets developers/application probe the current platform any of the supported classes, APIs, contracts, etc.

On Windows 8.1 Universal App:

#if Windows_Phone_App

Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_Pressed


On Windows 10 App:



Windows.Phone.UI.Input.HardwareButtons.Backpressed += HardwareButtons_BackPressed;


Since the HardwareButtons class and the Backpressed event is infact included in the UAP, even though the runtime type does not exist in the current device, there is no need for conditional compilation.

Instead of using IsTypePresent, you can test for the presence of individual members by using IsEventPresent, IsMethodPresent, IsPropertyPresent, and similar methods.

The set of APIs within a device family is further broken down into subdivisions known as API contracts. And you can use the ApiInformation.IsApiContractPresent method to tests for the presence of an API contract. This is useful if you want to test for the presence of a large number of APIs that all exist in the same version of an API contract.

public boolean HasScannerApi




return Foundation.Metadata.ApiInformation

.IsApiContractPresent("Devices.Scanners.ScannerDeviceContract", 3);



Windows 10 Changes

Other than the basic concepts in the development methodology, there are also changes in the framework and app model itself.

Continuation Manager No More (Windows Phone)

The infamous continuation context and the continuation manager are completely removed from windows phone to create a more unified programming model.
The methods that provide a continuation context such as FileOpenPicker.PickSingleFileAndContinue or WebAuthenticationBroker.AuthenticateAndContinue are replaced with their Windows Runtime counter parts such as FileOpenPicker.PickSingleFileAsync, WebAuthenticationBroker.AuthenticateAsync.

Charms Bar No More (Windows)

A concept that was introduced with Windows 8, the so-called charms bar, has been removed from Windows 10. In order to support the Windows 8 applications running on Windows 10, a top navigation button is introduced to access the charm functionalities like settings or sharing contracts.




For windows 10 applications, this top menu item does not appear. It is the developer’s responsibility to make these contracts accessible either with an app bar button or a button in the application interface.



Another change related to the charms is that the flyouts related to the charm bar buttons, such as the settings flyout; does not appear in the side of the whole client window but rather uses the application window.

Changing Layout Concepts (Windows)

Windows application on Windows 8 two separate models of layout. First one was the full screen layout, and the second one was the snapped layout. Snapped layout was initially a fixed half window sized view but later changed to an adjustable window.

Windows 10 - Tablet Mode

Windows 10 – Tablet Mode

Windows 10 user interface can be used in two different modes. One is the tablet mode, which resembles to the previous layout and the application is visible either in snapped or full screen views. The second mode is the desktop mode, which makes the windows runtime apps visually no different than classic windows applications. On the desktop mode, the applications can be moved by the user or resized as desired.

App Bar (Windows)

App bar is still accessible and usable in Windows 10 applications. The only change is the fact that now the app bar became part of the window that is presenting your application. This change does not affect the developers directly, only directed towards the user experience.

However, windows 8 applications running on Windows 10 still display their app bar just like before.

I tried to give a quick overview of the changes related to Windows 10. Overall, Windows 10 is coming with a lot of surprises both for developers and users.
Happy coding every one,