by Wojciech Sura

How to write an MP3 player?

Impressing friends when you’re a programmer is actually quite a hard task. We have to accept the fact, that the overwhelming majority of the population associates the word “class” with a chalkboard and mostly probably won’t see the beauty of, for instance, virtual treeview control boosted up by item position cache, which is generated dynamically on request in a separate thread. Sigh.

So let’s try something simpler and easier to show our non-technical friends: we’ll write an mp3 player in just nice round 16 lines of code.

You’ll need NAudio package.


Create an empty Windows Forms project and let’s write our 16 lines.  First of all, add two using’s to the code.

using NAudio;
using NAudio.Wave;

You’ll have to add the following fields to the form class.

private IWavePlayer waveOut;
private AudioFileReader reader;

Then initialize the waveOut object in form’s constructor.

public Form1()
    waveOut = new WaveOut();

Create two buttons on the form. Call first “Open and play” and second “Stop”. Now implement first button’s Click event:

private void button1_Click(object sender, EventArgs e)
    OpenFileDialog openDialog = new OpenFileDialog()
        Filter = "Music files (*.mp3)|*.mp3"

    if (openDialog.ShowDialog() == DialogResult.OK)
        reader = new AudioFileReader(openDialog.FileName);

Finally, implement second button’s Click event:

private void button2_Click(object sender, EventArgs e)

And that’s all! Compile the application and run. Enjoy!

by Njål

Fixing HttpException 0x80004005 / COMException 0x80070001

When getting HttpContext.Current.Request.Params in a C# .NET IIS website – we got this error several times a day:

System.Web.HttpException (0x80004005): An error occurred while communicating with the remote host. The error code is 0x80070001. —> System.Runtime.InteropServices.COMException (0x80070001): Incorrect function. (Exception from HRESULT: 0x80070001)
at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
at System.Web.Hosting.IIS7WorkerRequest.ReadEntityCoreSync(Byte[] buffer, Int32 offset, Int32 size)
at System.Web.HttpRequest.GetEntireRawContent()
at System.Web.HttpRequest.GetMultipartContent()
at System.Web.HttpRequest.FillInFormCollection()
at System.Web.HttpRequest.EnsureForm()
at System.Web.HttpRequest.get_Form()
at System.Web.HttpRequest.FillInParamsCollection()
at System.Web.HttpRequest.GetParams()


Turns out that this is related to various offloading done by the Network Card (NIC) – meaning that the NIC is doing stuff on its own which the OS/IIS doesn’t always like. Go to the network card properties – and disable these features:

  • Flow Control
  • Ipv4 Checksum Offload
  • Large Send Offload V2 (IPv4)
  • Large Send Offload V2 (IPv6)
  • TCP Checksum Offload (IPv4)
  • TCP Checksum Offload (IPv6)
  • UDP Checksum Offload (IPv4)
  • UDP Checksum Offload (IPv6)




Also – make sure you disable Power Management for the NIC.




by Wojciech Sura

How to diagnose your Samsung phone

Most of smartphone owners mostly probably already heard about service codes (“diagnostic”, “magic” etc.) for their phones. Such codes are entered in the dial screen and allow access to restricted parts of the phone. Some of them modify phone’s internal settings and sometimes may even damage the phone if not properly used.

There’s one special code though, which works on most Samsung devices with stock firmware, is safe to use and provide some useful diagnostic information about the phone.

Open the dial screen and type: *#0*# . Backlight of the phone will be boosted to maximum and a new menu will appear, allowing testing most of phone’s features.

Diagnostic menu

Among these you will find filling the display with single color (red, green, blue, black), testing the vibration engine, display dimming, checking both cameras, checking status of all sensors, testing touchscreen (also screen hover and S-pen if device supports these features), speakers, phone keys, notification LED, IR LED and more.


Note, that exiting from most diagnostic screens require double back-key press.

by Njål

“Insufficient storage available” when updating Android Apps

A few days ago I started to get the error “Insufficient storage available” when updating Apps on my Samsung S4 – running Cyanogenmod 11. I Googled it – and was recommended me to install various “cleaning” Apps – and also make sure I wasn’t out of storage space – which I wasn’t.



What actually fixed the problem was to open File Manager (which comes with Cyanogenmod) – and deleting folders inside /data/app-lib/ for the Apps that refused to be updated. Often the Apps had several folders – indicating that an Update had beenattempted – but failed. Delete all folders related to the App.




The folder names might not correspond 100% with the name of the App. If you are unable to find the folder for an App – then simply go to Settings > Apps > XXXXX and look at the namespace (marked in red below). The folder will have this name as well.



by Stian

Phishing/Spam: iTunes Store -Thank you for your purchase

Please be aware of the following iTunes Store scam e-mail circulating these days.
The e-mail should be deleted and requires no other actions from you.


From: iTunes Store <>
Subject: Thank you for your purchase

Dear customer,

This is an automated reply, but your Apple ID was just used to download Football Manager Handheld 2014 from the App Store on a computer or device that had not previously been associated with that Apple ID.

Order Number: QAPPCCVW21RCSW
Order total: 9.35 ?

If you initiated this download, you can disregard this email. It was only sent to alert you in case you did not initiate the download yourself.
If you did not initiate this download, we recommend that you go to iTunes Payment Cancellation Form to change your password, then
See Apple ID: Tips for protecting the security of your account for further assistance.

How to resume Payment Cancellation Form iTunes Store downloads

Please do not reply to this email. Thank you for your patience.
iTunes Store Customer Support

Apple ID : yourÉ
Lang_Country : en_UK
Product : iTunes Store
Support Subject : iTunes Store
Sub Issue : Connecting to iTunes Store with computer
See additional info below
What device did you use to connect to the store? Windows computer (PC)
Choose the iTunes Store or App Store for your country: United Kingdom



by Andreas

Selenium – Working with dynamic ASP.NET controls

Selenium LogoI recently had to find a replacement for our extensive Watin UI test framework. The reason being problems as a result of the IE11 release, and that Watin seems to have been abandonded in April 2011.

The choice landed on Selenium, which seems to be the de facto standard these days. It allows you to test in a variety of browsers, and is very much alive and kicking. There’s a .NET web driver available as a NuGet package, which makes it very easy to get started. But this isn’t a post about how great (or not?) Selenium is, it’s just a tip for those who’s using it for ASP.NET projects and came across the same annoyance as I did.

Selenium doesn’t handle dynamic ASP.NET controlId’s very well. It says in the docs that they recommend using static id’s, but seriously.. For projects before ClientIdMode was supported (< 4.0) this simply wasn’t an option. And should we go through thousands of lines of code and change this? I think not.

The solution is using XPath. Which, in Selenium’s defence, is supported. But it’s ugly, compared to using RegEx which was supported by Watin. Take the following example:

    <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>


To reference this textbox control, Selenium out-of-the-box requires this:

IWebElement e = driver.FindElement(By.XPath("//input[@id[substring(.,string-length()-7)='txtEmail']]"));


That’s not pretty. And you have to calculate the length of the controlId, take zero base into consideration (8 minus 1 = 7) and you will hopefully get a working reference. My preferred solution would be to add an extension to the By class, like By.RegEx() or something. But it’s a static class and extension methods require you to create an instance of it, so I had to scrap that idea (something for the next version of C#, Microsoft??)

My second best solution was a set of helper methods to generate the ugly XPath string. I’ve implemented a couple of options, where one get’s a reference without taking the type of control into consideration while the other allows you to look specifically for a textbox (input).

public class SeleniumTools

       public static string GetXPath(string controlId)
            return GetXPath(controlId, "*");

        public static string GetXPathForTextBox(string controlId)
            return GetXPath(controlId, "input");

        private static string GetXPath(string controlId, string controlType)
            return "//" + controlType + "[@id[substring(.,string-length()-" + (controlId.Length - 1) + ")='" + controlId + "']]";


At least this makes it a bit easier to read, and you don’t have to work out the XPath string manually:

IWebElement e = driver.FindElement(By.XPath(SeleniumTools.GetXPath("txtEmail")));
by Aage Andre

BSOD – process1_initialization_failed

After an afformentioned power-loss, one of the guest-vms started BSOD’ing during boot. Safe mode was no go, and only recovery worked.

Found a tip:

– Copy ‘C:WindowsSystem32CodeIntegritybootcat.cache’ from a working, similar server (2008R2 in this case) to a cd or usb-drive.
– Since this was a Hyper-V guest I created a ISO with the file, using ImgBurn, and mounted the iso inside the guest, while in recovery mode.
– Delete the original bootcat.cache from the system, and copy the working one you got from the other server.
– Reboot.

by Aage Andre

Windows Server 2012R2 reboot loop

One of our hosts ran into a reboot loop after an unplanned shutdown(also known as powerloss). When booting again, the server went straight from booting to shutting down services and rebooting.

Windows update is often the problem when boot-problems occur in my experience. So, boot into recovery mode and command prompt, and remove the file C.WindowsWinSXSpending.xml.

Reboot the server and no updates messing with your host during boot.


by Stian

Check if element is hidden with jQuery


Expert solutionJust another quick jQuery help post; how can I check if an element is visible or hidden using jQuery?

To check this for a single element, you can write:

// Checks for display:[none|block], ignores visible:[true|false]

You can also have a selector which gives you all hidden elements:

// Matches all elements that are hidden

or of course all visible elements:

// Matches all elements that are visible.
by Joakim

Using WinMerge as the default diff/merge tool in Visual Studio 2012/2013

Updated: The procedure described below also works for Visual Studio 2013!

I found the default diff/merge tool in Visual Studio 2012 to be a huge improvement over previous versions, as now you are actually able to see what has changed quite easily.


But that being said, I still prefer to use WinMerge as the default diff/merge tool since it has more features. Another nice feature of WinMerge is the possibility to integrate it into Windows Explorer which allows me to diff files (and folders) on my hard drive.

So how do you make WinMerge the default diff/merge tool in Visual Studio?

Go into “Tools –> Options –> Source Control –> Visual Studio Team Foundation Server”, click on “Configure User Tools …”, and add new commands for the “Compare” and “Merge” operations.



Values for the compare command;
Extension: .* (meaning all files)
Operation: Compare
Command: C:Program Files (x86)WinMergeWinMergeU.exe (the path to where WinMergeU.exe is located)
Arguments: /e /u /wl /dl %6 /dr %7 %1 %2 (the arguments for WinMerge, I’ll explain them in detail further down)

Values for the merge command;
Extension: .*
Operation: Merge
Command: C:Program Files (x86)WinMergeWinMergeU.exe
Arguments: /e /u /wl /dl %6 /dr %7 %1 %2 %4

After you add these two commands, right-clicking a file in Visual Studio and selecting “Compare…” should result in the two files being opened and compared in WinMerge. Should you want to go back to using Visual Studio’s own diff/merge tool, you just remove the two commands again.


So what do the values used in the arguments field in the two commands actually mean?

Values starting with a forward slash (/) are WinMerge command-line parameters. The full list of possible parameters can be found here. But I’ll list the ones I use (not all of them are necessary, you may remove some or add others as you prefer):

/e –> Enables you to close WinMerge with a single Esc key press
/u –> Prevents WinMerge from adding either path (left or right) to the Most Recently Used (MRU) list
/wl –> Opens the left side as read-only
/dl –> Specifies a description in the left side title bar
/dr –> Specifies a description in the right side title bar

Values starting with a percentage sign (%) are provided by Visual Studio as input for the WinMerge parameters. You can see what they stand for by clicking the “play” button behind the arguments field when you create the command, but I’ll list them here as well (I’ve greyed out those I don’t use):

%1 –> Original file
%2 –> Modified file
%3 –> Base file
%4 –> Merged file
%5 –> Diff command-line options
%6 –> Original file label
%7 –> Modified file label
%8 –> Base file label
%9 –> Merged file label

WinMerge can be downloaded the from here.