SourceTree Issue: This is not a Valid Working Copy Path

Introduction

We will discuss a quick tip to resolve the SourceTree issue mentioned in the title.

Background

My system got upgraded to Windows 8.1 and I had to install all required software for the development work. I use SourceTree as a tool for Git commands for the projects. So, I installed that again after the format.

Problem

Unfortunately, when I started adding the projects as working copy, it complained me that “This is not a valid working copy path“. The error is not so much self explanatory, which triggered research work.

Solution

Before I landed upon the solution, I had visited all available menu options in SourceTree to find out the problem. Finally, something engrossed me. I was on Git Tab.

Tools -> Options -> Git

I found some buttons saying “Use Embedded Git“, “Use System Git” at the bottom. So, I suspected that Git is not yet enabled for SourceTree. Therefore, it is not able to identify my commands. I enabled it, that’s why it is shown as disabled below.

SourceTree Git Settings

SourceTree Git Settings

Voila!!! Everything started working as expected.

Help Someone

Share in your circle. Hit the social icons below. Keep coding folks.🙂

Thanks for reading, have a great day ahead.

Visual Studio Error

Unable to Start Debugging on the Web Server. The Web Server is not Configured correctly.

Visual Studio Error

Visual Studio Build Error

Introduction

This blog is regarding one issue which happened couple of days back while building a demo app.

Background

One of the freshers in my company had this issue and I tried to resolve. The opportunity is huge, when you try to put yourself in their boot. They do crazy things and break the application. However, as my tech name is “BugTrapper“, so I started my research.

Problem

Then I found that the application is hosted in IIS with an IP in the binding.

iis-binding

Binding in IIS

Now, I wanted to check the Project Url in the Project Properties. This is what I saw.

project-properties

Project Properties

So, it’s obvious now. The problem is the URL mismatch.

Solution

I just updated the Project Url to the IP mentioned in IIS. Voila!!! All started working at the next moment.

Have you ever Faced This?

If yes, please comment below. Let’s discuss. Like and share if you want to save someone’s time.🙂

Uncaught IndexSizeError: Failed to execute ‘getImageData’ on ‘CanvasRenderingContext2D’: The source width is 0.

Introduction

In this post, we will discuss a problem, which I recently came across while working with images in coding.

Background

The work was to take one image from the file upload control and then compress it using canvas before uploading it to the server. I used a plugin, but let’s not go into that. We will directly come to the point where this problem can happen.

Problem

So, the line that we are talking about is like below.

var canvas = canvas.getContext('2d')
                   .getImageData(0, 0, imgWidth, imgHeight);

We are sending image width and height to getImageData. However, if you analyze the error message, it says that width is 0.

Solution

With further research on developer console while debugging, I found that the width and height are actually populated in some other properties named as naturalWidth and naturalHeight.
Therefore, we can write the code like below.

var imgWidth = image.width || image.naturalWidth;
var imgHeight = image.height || image.naturalHeight;

var canvas = canvas.getContext('2d')
                   .getImageData(0, 0, imgWidth, imgHeight);

Now your program should work as expected without errors.

More on naturalHeight and naturalWidth from MDN

HTMLImageElement.naturalHeight (Read only)
Returns a unsigned long representing the intrinsic height of the image in CSS pixels, if it is available; else, it shows 0.
HTMLImageElement.naturalWidth (Read only)
Returns a unsigned long representing the intrinsic width of the image in CSS pixels, if it is available; otherwise, it will show 0.

Feedback

If you like this blog, feel free to share it in your circle and save someone’s time. Please comment below, if you have any inputs for me.

Thanks for reading. Have a nice day ahead.

SourceTree Issue: The Mercurial team strongly encourages all users to upgrade to 3.7.3 due to security vulnerability

Introduction

If you see the above issue when you update the SourceTree, then follow the steps mentioned below to resolve it. Those who don’t know, it is a free Git and Mercurial client for Windows or Mac, which makes source code management easier with a GUI.

Background

I appreciate how the SourceTree team is continuously improving the software and making it more user friendly. But today, when I updated it to the latest version and opened it again, I saw a weird issue popped up, instead of the SourceTree window.

SourceTree Error

The issue is…

The Mercurial team strongly encourages all users to upgrade to 3.7.3 due to security vulnerability

What is Mercurial?

Mercurial is a free, distributed source control management tool. It efficiently handles projects of any size and offers an easy and intuitive interface.

Problem

The version of the Mercurial on your system is old and it has some security vulnerability, which they have fixed and updated with the latest version. If we dig more into the upgrade notes, the below is what you will find.

Mercurial Security Vulnerability Fixes

Solution

Go to Mercurial Download Page. Download the latest package according to your system configuration. Now, SourceTree should work as expected.

Mercurial Downloads

Microsoft MVP April 2016

Microsoft MVP 2016

Microsoft MVP 2016

Wow!!! What a surprise on a Friday.
Awarded as ‪Microsoft‬ MVP for the “third time in a row”.

Read my Story

Here. Also by my CEO Mr. Chinmoy Panda. He narrates my story in his own words. Celebrating Awesomeness

What is Microsoft MVP?

Answer : Click here to know more.

The Microsoft Most Valuable Professional (MVP) Award is our way of saying thank you to exceptional, independent community leaders who share their passion, technical expertise, and real-world knowledge of Microsoft products with others. It is part of Microsoft’s commitment to supporting and enriching technical communities. Even before the rises of the Internet and social media, people have come together to willingly offer their ideas and best practices in technical communities.

Thanks to…

  • Biplab Paul, Gandharv Rawat for believing in me. Thanks Siddharth Rout for polishing my skills before the first award in 2014.
  • Thanks to all MVPs in my network.
  • Thanks to my friends, colleagues and leads, who always support and encourage me. Special thanks to Debasis Behera who pulled me to The Code Project (www.codeproject.com) for answering questions. That was my baby step towards tech community activities. Kshirodra Meher, Sibasis Jenaand Deepak Jena and Tapan Khatua – these geeks help me sharpen my knowledge.
  • My family has been a great inspiration, which propels me for hard work. Thanks Grandfather (Mr. Ganeswar Tripathy) for guiding me. I miss you.😦
  • Last, but not the list, my heartiest gratitude to the members of Microsoft Dev Community, Odisha. Without them, I am nothing.

Thanks almighty, Jay Jagannath!!!

Detect Changes to Spectrum Colorpicker

Introduction

In this blog, we will see how to manage the default value of color picker so that we can detect if color is changed.

Background

In my current project, requirement came to check if there are changes on the page on a button click and show a modal alerting the user that “There are changes, do you want to save?”. I found a script which can be triggered to check the changes on the page. It worked perfectly with all input, select and textarea controls.

But if I have a colorpicker on the page, then it always told me that you have changes, even if I did not change the color in the picker. Let me explain more. The colorpicker used is Spectrum.

Step by Step

Suppose, I have one input, select and textarea on my page. One button to check if we have any change on these controls meaning if we edited/changed the field values.

<input />

<select>
    <option value="1">1</option>
    <option value="2" selected="selected">2</option>
    <option value="3">3</option>
</select>

<textarea>Hello World</textarea>

<button onclick="CheckForChanges()">
    Check For Changes
</button>

Now let’s check the click event code.

function CheckForChanges() {
  if (GetHasChanges()) {
      alert("Yes we have changes!!!");
  } else {
      alert("No changes!!!");
  }
}

I am not posting the GetHasChanges function here, you can see in the jsfiddle Demo.
So, see the picture below which tells what is before you click the button and what happens after you edit some field and click the button. It perfectly checking that we have a change.

Before and After Changes Done

Before and After Changes Done

With Colorpicker

Let’s add a colorpicker now.

<input id="colorpicker" style="display:none;" value="#000" />
$(document).ready(function() {
  $('#colorpicker').spectrum({
    preferredFormat: "hex"
  });
});

Demo – Demo With a Colorpicker
As you see in the picture below, everything is perfect.

Detecting Changes with Colorpicker

Detecting Changes with Colorpicker

Implementing Input Field inside the Colorpicker

This can be done by setting the showInput property to true

$(document).ready(function() {
  $('#colorpicker').spectrum({
    showInput: true,
    preferredFormat: "hex"
  });
});

Spectrum Colorpicker With ShowInput True

Spectrum Colorpicker With ShowInput True

What we get by doing this? Just a new input field inside the colorpicker so that we can give color hex.

Let’s get back to what we were doing.
OOPS!!! With no change, it is now saying that “Yes we have changes!!!”. See the picture below.

Checking changes with ShowInput true in Spectrum Colorpicker

Checking changes with ShowInput true in Spectrum Colorpicker


Demo – Demo to check changes with ShowInput true in Spectrum Colorpicker
So, I have not picked any color, still its detecting changes. We will find out the problem in next paragraph.

Research

I started research from Developer tool and debugged the method which is checking the changes. What I found, was very interesting.

Debugging GetHasChanges Function in Developer Tool

Debugging GetHasChanges Function in Developer Tool


So, as you see, it is detecting the change for an input. I, then, found it inside the HTML.

<input class="sp-input" type="text" spellcheck="false">

This is the same input which is inside the colorpicker. The problem it detected a change because it does not have a default value in place and value given to it is the color we provided (#000).

Solution

Have you guessed the solution!!! It’s easy. We just need to provide the default value as the same color value. Thus, it will only detect the change when an actual change is made. The final code looks like below. Highlighted the codes used to assign the default value.

$(document).ready(function() {
  $('#colorpicker').spectrum({
    showInput: true,
    preferredFormat: "hex"
  });

  $('.sp-container .sp-input').each(function() {
    this.defaultValue = this.value;
  });
});

Demo – Final Demo Detecting Colorpicker Change

Feedback

I would definitely appreciate, if you give feedback to my blog. If you find it interesting and useful, then please share with your friends and colleagues.

Thanks for reading, have a nice day!!!

Get Required Property from Complex json string in C# with Newtonsoft

Introduction

In this blog, I will tell you the trick to convert JSON string property to C# Object using Newtonsoft.

Illustration

Suppose the JSON string is like…

{
  "Success": true,
  "ComplexObject": {
    "NormalProp": "Test",
    "ListOfAnotherClass": [{
      "JustAStringProp": "We"
    }, {
      "JustAStringProp": "Got"
    }, {
      "JustAStringProp": "Values"
    }]
  }
}

Now, if I get this string from some method and try to process, I would need to convert this to C# objects. The structure would look something like below. To easily get the class structure, you can use any online tool like json2csharp.

class Result
{
	public bool Success { get; set; }
	public ComplextJsonClass ComplexObject { get; set; }
}

class ComplextJsonClass
{
	public string NormalProp { get; set; }
	public List<AnotherClass> ListOfAnotherClass { get; set; }
}

class AnotherClass
{
	public string JustAStringProp { get; set; }
}

What We Need?

So, for processing, I would like to get the “ComplexObject” property of this JSON string converted as “ComplextJsonClass” C# object. As the JSON string is complex with other property like “Success“, we only need the property “ComplexObject“, yet converted to a C# object.

How To Do That?

We will use Newtonsoft. You can easily find that from Nuget and add that as a reference to your project.

Solution

First of all, I will tell you how to generate this type of JSON.

var complex = new ComplextJsonClass
{
	NormalProp = "Test",
	ListOfAnotherClass = new List<AnotherClass>
	{
		new AnotherClass{JustAStringProp = "We"},
		new AnotherClass{JustAStringProp = "Got"},
		new AnotherClass{JustAStringProp = "Values"},
	}
};

var moreComplex = new Result {Success = true, ComplexObject = complex};
var jsonString = JsonConvert.SerializeObject(moreComplex);

This “jsonString” comes as I mentioned in the beginning of the post. Now, we need to convert this JSON to a C# Object. For this, we need to use JsonConvert.DeserializeObject Method (String).

var jsonObject = JsonConvert.DeserializeObject(jsonString);

But, unfortunately, this alone won’t help us more to access the properties. We have to convert to a JObject, by which we can easily access the properties from the JSON.

var jsonObject = (JObject)JsonConvert.DeserializeObject(jsonString);

After this, it is just a matter of getting the property by using jsonObject["ComplexObject"].

var jsonObject = (JObject)JsonConvert.DeserializeObject(jsonString);
if (jsonObject["ComplexObject"] == null) return;

ComplextJsonClass complexObject = JsonConvert.DeserializeObject<ComplextJsonClass>
            (jsonObject["ComplexObject"].ToString());
Convert to C# Object from Newtonsoft JObject

Convert to C# Object from Newtonsoft JObject

Full Code

var complex = new ComplextJsonClass
{
	NormalProp = "Test",
	ListOfAnotherClass = new List<AnotherClass>
	{
		new AnotherClass{JustAStringProp = "We"},
		new AnotherClass{JustAStringProp = "Got"},
		new AnotherClass{JustAStringProp = "Values"},
	}
};

// Get the jsonString from complex object.
var moreComplex = new Result {Success = true, ComplexObject = complex};
var jsonString = JsonConvert.SerializeObject(moreComplex);

//Now let's deserialize and convert to our required ComplextJsonClass object.
var jsonObject = (JObject)JsonConvert.DeserializeObject(jsonString);
if (jsonObject["ComplexObject"] == null) return;

ComplextJsonClass complexObject = JsonConvert.DeserializeObject<ComplextJsonClass>
            (jsonObject["ComplexObject"].ToString());

Feedback

Let me know if this trick helped you in any way in your projects or assignments. Re-post or share, if you liked it.

Thanks a lot for reading. Marry Christmas and Happy New Year.🙂