String to Guid with MD5 hashes for .NET and SQL Server

If you need to convert a string value to Guid you can use MD5 hashes. They are always having a length of 128 bits and therefore can be converted to a Guid.

Why you may want to do this?

In my project I’m having a big database containing some very long text values. I needed a way to quickly compare and query them. In Sql Server indexed columns does have a maximun length and in my case the limit was exceeded. Storing the hashes of big text values in the database is a good option for that. You can add an index to the Guid and query quickly.


This example converts a string to Guid in C#

        /// <summary>
        /// Convert string to Guid
        /// </summary>
        /// <param name="value">the string value</param>
        /// <returns>the Guid value</returns>
        public static Guid ConvertToMd5HashGUID(string value)
            // convert null to empty string - null can not be hashed
            if (value == null)
                value = string.Empty;

            // get the byte representation
            var bytes = Encoding.Default.GetBytes(value);

            // create the md5 hash
            MD5 md5Hasher = MD5.Create();
            byte[] data = md5Hasher.ComputeHash(bytes);

            // convert the hash to a Guid
            return new Guid(data);



Turn off Visual Studio Attach security warning when debugging IIS

I found this post and it works. But note that you need to close Visual Studio before you update the registry, otherwise your changes will be overriden.

Windows Registry Editor Version 5.00



Version 12 means Visual Studio 2013

Windows Ribbon for WinForms in Visual Studio 2013

The Windows Ribbon project is still working in Visual Studio 2013. Now I will show you the steps I did to get it working.

Download and install Windows 8.1 SDK

Windows 7 SDK is also enough.

Bild 156

Download the Latest Ribbon Sources

Bild 152

Get the RibbonGenerator compiling

The download is below. You do not need this.

Bild 153

Microsoft.VisualStudio.Shell not found?

Bild 154 Bild 155

 Download Visual Studio 2013 SDK

Bild 157

Bild 158

Bild 159

Switch the target of the RibbonGenerator

Bild 160

Bild 161

Now it should compile.

Download the Ribbon Generator for Visual Studio 2013

Note that it this one will only work for VS 2013. Download contains RibbonGenerator binaries and source.

Register the Ribbon Generator (Custom Tool)

- Create a .reg file and import it. This one will only work with VS 2013 and a x64 Windows.

Windows Registry Editor Version 5.00</pre>
"Assembly"="RibbonGenerator, Version=, Culture=neutral, PublicKeyToken=3cf107c5d7e68b1c"

@="Ribbon Generator"

@="Ribbon Generator"

@="Ribbon Generator"

- Open Cmd as Administrator

- Use the correct version of gacutil.

“C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\gacutil.exe” -i “C:\…\RibbonGenerator.dll”

Check RibbonGenerator Registration

Check that Ribbon Generator is working correctly.

- Open the Ribbon-cs.sln solution

- Right-click on RibbonMarkup.xml and click Run Custom Tool

Bild 167

The following screenshot means, you have done a mistake in the previous steps.

Bild 166

Update the template.bat

No error occurred, but still not work? Check that all the tools are on your hard disc. Check all pathes to be  correct …


"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin\UICC.exe" "{XmlFilename}" "{BmlFilename}" /res:"{RcFilename}"
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin\rc.exe" /v "{RcFilename}"
cmd /c "("%VS120COMNTOOLS%..\..\VC\bin\vcvars32.bat") && ("%VS120COMNTOOLS%..\..\VC\bin\link.exe" /VERBOSE /NOENTRY /DLL /OUT:"{DllFilename}" "{ResFilename}")"

Other Ribbon Posts

Quickstart Tutorial: Windows Ribbon for WinForms
RibbonGenerator Details: Windows Ribbon for WinForms
RibbonGenerator for Visual Studio 2010 Express Editions: Windows Ribbon for WinForms

GeoLocator.GetGeopositionAsync With Correct Timeout

To get the current user position in Windows Phone 8 you can use the GeoLocator class that is very comfortable. You get a method containing two overloads.

  • GetGeopositionAsync() – return the current postion (does not have a timeout)
  • GetGeopositionAsync(maximumAge, timeout) – returns a cached position

Sometimes GetGeopositionAsync does not return. So you need to add a timeout procedure by your self. This way is works perfect.

            Geolocator geolocator = new Geolocator();

            // get the async task
            var asyncResult = geolocator.GetGeopositionAsync();
            var task = asyncResult.AsTask();

            // add a race condition - task vs timeout task
            var readyTask = await Task.WhenAny(task, Task.Delay(10000));
            if (readyTask != task) // timeout wins
                throw new TimeoutException();

            // position found within timeout
            var pos = await task;
            return pos;


Code Reuse Analysis: Portable Libraries for Windows 8 and Windows Phone 8

I have written apps for both systems – Windows 8 and Windows Phone 8 by using portable class library to share and reuse code. Some people like to know how much synergy you will get while developing apps the two systems.

Analysis key figures


Part of the analysis is a single project.


The Windows 8 app and the Windows Phone 8 app are having about 80 percent of features in common. Round about 20 percent are specific features that are unique to one platform.


The project is done by using MVVM pattern. Models, View-Models and Services are part of portable libaries. While the views, all the UI stuff and the background tasks (agents) are part of the platform libraries.


In the Windows 8 app there are 10 views and 7 views in the Windows Phone 8 app.

Analysis Results

I think the best way it to compare the lines of code of the projects. I’m using the Code Metrics feature in Visual Studio to find out the values. So please be aware, that XAML is not part of the analysis.

All Lines of Code: 4887 = 100%

  • Portable Class Library: 2580 = 53%
  • Windows 8 and Windows Phone 8: 2307 = 47%
    • Windows 8: 866  = 17%
    • Windows Phone 8: 1100 = 22%

As you can see, in my project I was able reuse about 50% of the whole code by using portable class libaries.

Localhost connection fails in Unit Test Project

Windows 8 Store apps are not allowed to connect to localhost using any network connection type like a simple http request. For developers Visual Studio 2012 automatically exempts your Windows Store App projects by putting them into the right isolation level, but for your Unit Test projects Visual Studio does not do the same. So, to connect to localhost – or just if you are using Fiddler – in your Unit Test project , you have to manually put them in to the “exception list”.

Open a command line window and check, if your Unit Test project is in the correct isolation level.

CheckNetIsolation Loopbackexempt -s

Add your Unit Test project to the list

CheckNetIsolation Loopbackexempt -a -n=<package familiy name>

You can find your “package familiy name” in the “package.appmanifest” file of your Unit Test project in the Packaging tab.

PortiLog – Logging for Portable Class Libraries

The first version of PortiLog is available now. It is a small but simple library to write and monitor app log files. Windows 8 Store Apps and Windows Phone 8 Apps are supported.

Documentation and Samples here…


Get every new post delivered to your Inbox.