Failed to add reference to Microsoft.Synchronization

Failed to add reference to ‘Microsoft.Synchronization’. Please make sure that it is in the Global Assembly Cache

If you are getting the same error while installing Nuget for Microsoft Sync Framework. It looks like you have not install the framework SDK.

Download the latest Microsoft Sync framework SDK (https://www.microsoft.com/en-au/download/confirmation.aspx?id=23217)
Once the SDK is installed, Nuget finds the failing references in Global Cache and install rest of it without any complain.

Hide PowerPoint slide show on second monitor

Have you ever been annoyed by duplicate slide show on second monitor? Read further to get rid of it!

Microsoft Office comes with lot of features which are very handy but sometimes they are annoying if enabled by default and not fully understood.

I work with two monitors and quite often use PowerPoint for presentation and demos. Since upgraded to Office 2013, I was getting annoyed by having my ppt run on both my monitors.

From a while, I was ignoring it thinking it the default behavior but today is the day when I stood up and said I had enough.

So I looked around, checked Office document and found a feature which was enabled by default.

Presenting you the “Presenter View” (definition shown in PowerPoint help)
“Presenter View allows you to see your notes on your monitor while the audience only sees the slide. In previous releases, it was difficult to figure out who saw what on which monitor. The improved Presenter View fixes that headache and makes it simpler to work with.”

It is a new and handy feature in Office 2013. You can read more about it at https://support.office.com/en-my/article/View-your-speaker-notes-as-you-deliver-your-slide-show-4de90e28-487e-435c-9401-eb49a3801257?ui=en-US&rs=en-MY&ad=MY

Yes, it is good but wasn’t required on my dev machine. So had to get rid of it and it was just the matter of disabling it from Menu bar.

Go to (1) Slide Show Menu –> (2) UnCheck ‘Use Presenter View’ and you are done. You may want to choose (3) Monitor where slide show should pop up for you.

Disable Presenter View

Burj Khalifa ticket on more than 50% discount

I recently was buying the ticket for Burj Khalifa and notice if the ticket is booked over internet it is 50% or even more cheaper than buying from Burj itself. The difference to me is huge. The below screen shot taken on 11th November 2015 shows the price difference between tickets booked online and tickets taken immediately. Also to note the prices are same for all age group (except infant) when bought immediately.

So obvious recommendation, plan it in advance and buy it online. You may also save yourself from disappointment of not getting tickets at counter.

Burj Khalifa Ticket prices
Have a look at this official site for more information https://tickets.atthetop.ae/atthetop/
Enjoy the benefit of technology !!!

App not showing in purchased list of AppStore

Recently i got hit with an issue when few of my games and productivity apps were missing from purchased list in AppStore.

Furious to this nonsense issue, first thing I did was Google for help. I found many forums talking about various causes that’s leads to this problem. One of them even mentioned slow internet speed as problem.

Anyway after spending some time, I realized my problem occurred because I changed my iTunes store location.

The SOLUTION: AppStore shows the list of purchased apps based on its iTunes & App store location. Changing the location worked for me. It might work for you too, if that’s the case.

Screen recording in Android OnePlus

OnePlus with its custom OS has got a great app to make video of whatever you are doing on your phone. No ROOT is required for it, means no hacking or jailbreaking for Android.
One plus phones are factory loaded with ScreenCast, otherwise one can obtain it from Play store.

As soon you hit the application icon on your phone, it shows a message “Press ‘Start Screencast’ to begin recording a video of your android screen and microphone”
Once started, you can look at the notification area to stop it or to enabled/disable the touch.

There are no settings provided and default format is mp4 recorded at Full HD (1080×1920) resolution.

All the videos are saved in Gallery–>Screencast

Have a look at my other post where I used OnePlus one screencast to make video https://wordpress.com/post/100959924/150/

Be mindful to the size it creates. I made the video for about 1min 45s and the size was 56mb.

With other Screencast available at PlayStore offered by Kastor Soft, it provides good configuration like video/audio quality, delay, front camera recording, sampling rate and channel and also doesn’t require phone to Root.

Have a look at playstore https://play.google.com/store/apps/details?id=com.kerby.screencast&hl=en
Some of the other applications require Root (which I do not suggest for non-computer savvy people).

Disable carriage return in text area or multi line text box

I have seen many people getting tricked with it and implementing nasty solution to get around to it.
Using jQuery we can write a very concise and simple code to cancel the carriage return in multi line html box.

Have a look at below example

<head runat="server">
  <title></title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>

<form>

<div>
      Disable carriage return in text area or multi line text box
</div>


<div>
      <textarea id="txt1" aria-multiline="true"></textarea>
</div>


  <script type="text/javascript">
    $(function () {
      $('#txt1').keydown(function (eventArgs) {
        var code = eventArgs.keyCode;
        if (code == 13) {
          console.log('key prevented');
          eventArgs.preventDefault();
        }
      });
    });
  </script>
</form>

</body>

event.preventDefault() – as definition given at jQuery document here at jQuery
If this method is called, the default action of the event will not be triggered.

OnePlus one no service issue

With the release of new update Cyanogen OS 12.1 many people have faced issues mostly with losing mobile DATA connection. With me the problem was phone started dropping mobile service. Every minute or so the phone was showing “no service” and so neither I was receiving any call nor was able to make any. Even the messages were delayed for hours.

I checked various sites and forums, tried almost everything but nothing worked.

SOLUTION: I luckily found that issue was preferred network which was set to 4g. I changed it to 3g and wolla all started working fine. Made a quick 2 min video to show how it all happened.

Notice the network sign at top right and how it changes from service to no service couple of times within a minute. See how it becomes stable after changing to 3g.

Textual process: To do so go to Settings->Mobile networks->Preferred Network type and change it.

This could be because of sim or may be something else, m not sure whatever above solution worked for me.

Other resources to read

Write your comments if it helps.

is not a valid value for property ‘Top’ XAML

‘xxx’ is not a valid value for property ‘Left’ XAML

I got this error when dynamically setting the top and left attribute of child object having Canvas as its parent object. System didn’t allow me to do so and has not really given any impressive explanation other than the error message.

Invalid value for property

I don’t know what exactly happening behind the scene but I got it resolved by using Canvas’s SetTop and SetLeft instead of SetValue defined in DependencyObject class.

 
//Problem code 
childObject.SetValue(Canvas.TopProperty, 500); 
childObject.SetValue(Canvas.LeftProperty, 500); 

//alternative code using more direct Canvas SetTop and SetLeft 
Canvas.SetLeft(childObject, 500);
Canvas.SetTop(childObject, 500); 

Mobile data or 3G connection getting slow suddenly

Puzzled for more than a week, I became victim of latest technology offerings from one of the leading Internet Service Provider company in our area.
I use public transport to commute between home and office and spend 20-25 mins travelling time reading news and articles on my phone.

Few weeks earlier, I realize that as soon my bus approaches close to CBD, my news application almost dies. It doesn’t refreshes, doesn’t load the new news article fast enough and my leisure time was snatched from me. Blaming it on my service provider, then on bus speed, then on news app and lastly to my phone, ultimately phone use to slip back in my pocket.

Anyway, one day by fluke, I found the reason why it all started happening. The leading service provider, being so generous, announce free WIFI within the CBD. I was one of those who sign-in to enjoy free internet. But soon realised that it’s too slow, may be many hundred people using it and decided to go back to mobile data.

Yeah, I reckon that was the day since my 3g started acting strange.
As soon I approach close to CBD, the smart apps, giving preference to WIFI, use to pick internet source from WIFI instead of 3G mobile data. From that moment, my news article and any other internet browsing use to slow down drastically.

The SOLUTION: Switch off the WIFI and let mobile data be used for internet source.

There may be various reason of 3g or 4g getting slow, but this weird one happened with me and so the small post … why not!!!

C# short hand coding – Part 1

This part of blog include general quick tips for short hand c# coding. I’ll write more about specific and advance tips in further parts.

If else conditions

There are various ways we can short hand if else condition coding

//Example 1- if condition without curly braces
int age = 10;
if (age > 17)
  Console.WriteLine("Adult");
else if (age > 12)
  Console.WriteLine("Teenager");
else
  Console.WriteLine("Child");

//Example 2- if condition in single line
int age = 10;
if (age > 17) Console.WriteLine("Adult");
else if (age > 12 ) Console.WriteLine("Teenager");
else Console.WriteLine("Child");

//Example 3 - complete if condition in absolute single line
int age = 10;
if (age > 17) Console.WriteLine("Adult"); else if (age > 12 ) Console.WriteLine("Teenager"); else Console.WriteLine("Child");

?: conditional operator

The conditional operator evaluates boolean expression that appears prior ? mark. It returns value (expression) given between ? and : marks if evaluated true or value after : mark if evaluated false.

//? : conditional operator
int age = 18;
string AgeOfMajority = age > 17 ? "Adult" : "Teenager";
Console.WriteLine(AgeOfMajority); 

It compacts the if else condition from 3 or more lines to just one line.

?. and ? Null Propagating Operators C# 6

New to .net framework, it’s not an everyday operator that comes into use but if practiced enough, it is very handy when delve into 2-3 or more level of chained access.

I picked this example from MSDN, you may want to look into it https://msdn.microsoft.com/en-us/library/dn986595.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1

Definition as given on MSDN: Null Propagating operator test for null before performing a member access (?.) or index (?[) operation. These operators help you write less code to handle null checks, especially for descending into data structures.

// Length of customers if object is not null
int? length = customers?.Length;

// get first element if customers array not null
Customer first = customers?[0];

// getting count of orders if customers array is not null and first customer’s order is not null
int? count = customers?[0]?.Orders?.Count();

The last example demonstrates that null propagating operators are short-circuiting. If one operation in a chain of member access and index operation returns null, then the rest of the chain’s execution stops. Other operations with lower precedence in the expression continue.

+= Operator

This one of the handy operator avoids writing the variable name twice in case of adding for integer and appending for string types.
For example

//+= operator for string
string str = "Hello ";
str += "World";
Console.WriteLine(str);

//+= operator for integers
int cost = 50;
cost += 7;
Console.WriteLine(cost);

-= Operator

-= can only be applied to numeric types and give compile time error when used with string types

//+= operator for integers
int cost = 50;
cost -= 7;
Console.WriteLine(cost);

Similarly there are other arithmetic operators which are very handy. Read more at MSDN here https://msdn.microsoft.com/en-us/library/sa7629ew.aspx

Checking for bool condition

It may not even be worth mentioning but for some beginners and people not much familiar with nullable types it may be handy.


// using simple boolean check without using == operator
bool flightArrived = true;
if (flightArrived)
  Console.WriteLine("Dad home");
else
  Console.WriteLine("Waiting ......");

//For checking false condition use ! like 
if (!flightArrived)
  Console.WriteLine("waiting.....");
else
  Console.WriteLine("Dad is coming");

Nullable Boolean types

When using nullable boolean types, the above code will not compile. Nullable bool can contain True, False or Null. That’s the reason why above code will fail.
Hence to check, it has to accompany with .hasValue test with a conversion

// nullable boolean check
bool? flightArrived = null;
if (flightArrived.HasValue && (bool)flightArrived)
  Console.WriteLine("Dad home");
else
  Console.WriteLine("Waiting ......");

Null-Coalesce operator (??)

Null coalesce operator test and assign objects value if not null otherwise use alternative value given after ?? (double question mark)

bool? userLogged = null;

// Null test – if userLogged is null then assign false otherwise assign whatever it contains
bool test = userLogged ?? false;
Console.WriteLine(test.ToString());

TryParse

Try parse is sort of extended version of Parse, available to all value types. The benefit about it is that it doesn’t throw the null exception if string value doesn’t contain the right value. It is safe and short to validate and extract value from string object.
– Int32.TryParse
– Float.TryParse
– bool.TryParse

String Operations

String IsnullOrEmpty

A single method to check for Null and Empty string, very handy to keep it short.

string IsNullOrWhiteSpace

Checks for null and whitespace, return true or false based on test.

String.Join operation

string[] Users = new string[] { "John", "Mike", "Jag", "Harry", "Lila" };
string str = string.Join(",", Users);
Console.WriteLine(str);

Property creation

The one line code for creating a property for e.g.

public string FirstName { get; set; }
public string LastName { get; set; }

Framework internally creates the private variable, getter and setter for it.
Want to create the readonly property try this

public string FirstName { get;}

Class Initialization

Initialize and assigning the reference of a class to method or property.
Suppose I have a class called Hollywood actors


public class HollywoodActor
{
  public string FirstName { get; set; }
  public string LastName { get; set; }
}

//If I want to create the object and initialize its property, the normal code would be

HollywoodActor hollywoodActor = new HollywoodActor();
hollywoodActor.FirstName = "Arnold";
hollywoodActor.LastName = "Schwarzenegge";

//I can make it shorter by creating an overloaded constructor like 

public HollywoodActor(string firstName, string lastName)
{
FirstName = firstName;
LastName = lastName;
}

// and then create object and assign property from constructor
HollywoodActor hollywoodActor = new HollywoodActor("Arnold", "Schwarzenegge");

//The other quick short hand that I use is without overload constructor

public class HollywoodActor
{
public string FirstName { get; set; }
public string LastName { get; set; }
}

// Creating object of Hollywood actor class and assigning values
HollywoodActor hollywoodActor = new HollywoodActor()
{
FirstName = "Arnold",
LastName = "Schwarzenegge”;
};

//Example 2 - Creating list of Hollywood actors class and assign values
List actors = new List()
{
new HollywoodActor() { FirstName = "Tom", LastName = "Cruise" },
new HollywoodActor(){ FirstName = "Bruce", LastName = "Willis" },
new HollywoodActor(){ FirstName = "John", LastName = "Travolta" },
};

Event declaration and implementation

There are times when few code lines are written and a piece of work done within an event is written far from its logical grouping. It makes it readable it have it included at same location.

Shorthand can be achieved using lamda expression, for e.g. the simplest way of showing is to bind event at Form load event and write code as

btnTest.Click +=  (ss, ee) => 
    MessageBox.Show("Inline event implementation");
};