Friday, 23 May 2014

How to determine event subscriptions at runtime

Forgot this again, so thought I'd repost it...


Executing that in the immediate window will spawn you out a list of the attached event handlers to your event at runtime.

Also, if you're trying extract the invocation list of a dotNetBar ButtonItem control's click handler, then the following code is necessary due to the obsfucation of the code that dotNetBar controls have within them. The strange Convert.ToChar(2694) is required in order to ensure that the code page of the C# file remains as ANSI (or Windows 1252), instead of asking you to switch to UTF-8 if you use the actual character code that the private event is stored as.


var buttonItem = sender as ButtonItem;
            var clickHandler = string.Empty;
            if (buttonItem != null)

                var clickEvent = typeof(BaseItem).GetField(Convert.ToChar(2694).ToString(CultureInfo.InvariantCulture), BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);

                if (clickEvent != null)
                    var clickEventDelegate = clickEvent.GetValue(buttonItem) as Delegate;
                    if (clickEventDelegate != null)
                        var invocationList = clickEventDelegate.GetInvocationList();
                        if (invocationList.Length > 0)
                            clickHandler = invocationList[0].Method.Name;

                    "The click event {0} is yet to be implemented. If you're attached the debugger will now launch",
                    clickHandler), "Click event handler not yet implemented yet", MessageBoxButtons.OK, MessageBoxIcon.Information);

Wednesday, 21 May 2014

BrowserLink and other new VS 2013 features

Perhaps the most significant enhancement to creating web applications in Visual Studio for many years. Check out how you can edit your pages in line in the browser, and it updates the source code back in visual studio directly, using the new BrowserLink feature...

More features worth a look are all listed under the parent page here...

Remove capitalization from Visual Studio 2012 / 2013 menus

Manual Registry Change

Open the registry editor and go to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\General\
(For Windows 8 Desktop Express go to HKCU\Software\Microsoft\WDExpress\11.0\General) //special thanks to msm8bball for the update
(For Web Express go to HKEY_CURRENT_USER\Software\Microsoft\VSWDExpress\11.0\General)

  1. Create a new DWORD value called SuppressUppercaseConversion set to 1


PowerShell Goodness

In the PowerShell window copy the script below and paste it in then press Enter:
Set-ItemProperty -Path HKCU:\Software\Microsoft\VisualStudio\11.0\General -Name SuppressUppercaseConversion -Type DWord -Value 1

Tuesday, 20 May 2014

Starting IISExpress from command line

start "" "C:\Program Files (x86)\IIS Express\iisexpress.exe"  /config:"%userprofile%\Documents\IISExpress\config\applicationhost.config"  /site:"RRA.Web.McMuffin" /apppool:"Clr4IntegratedAppPool"

P.S. One of the many benefits I've discovered in starting IISExpress in this way from the command line, is that you get fiddler type page visit logging output for each page request in the resulting console window..


Macros in Visual Studio 2012 / 2013

Use the following visual studio extension in order to recreate the macros that you were used to using in VS 2010 and below
Also to run the macro, try using the Ctrl+Q shortcut menu in VS 2013, as follows

Or customise your toolbar

The attach to process macro will now look like this as a new Visual Commander command using VB v4.0 language
Imports EnvDTE
Imports EnvDTE80
Imports Microsoft.VisualBasic

Public Class C
    Implements VisualCommanderExt.ICommand

    Sub Run(DTE As EnvDTE80.DTE2, package As Microsoft.VisualStudio.Shell.Package) Implements VisualCommanderExt.ICommand.Run
        AttachToProcess("MyProcessName.exe", DTE)
    End Sub

    Private Sub AttachToProcess(ByVal ProcessName As String, DTE As EnvDTE80.DTE2, Optional ByVal Script As Boolean = False)
            Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
            Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
            Dim dbgeng(1) As EnvDTE80.Engine
            If Script Then
                dbgeng(0) = trans.Engines.Item("Script")
                'Array.Resize(dbgeng, 1)
                dbgeng(0) = trans.Engines.Item("Managed")
            End If
            Dim proc2 As EnvDTE80.Process2 = dbg2.GetProcesses(trans, System.Environment.MachineName).Item(ProcessName)
            Call proc2.Attach2(dbgeng)
        Catch ex As System.Runtime.InteropServices.COMException
            Select Case ex.ErrorCode
                Case -2147352565
                    ShowMessage(ProcessName & " is not currently a running process")
                Case -1989083106
                    ShowMessage("You are already attached to " & ProcessName)
                Case Else
                    ShowMessage("Unhandled error message from Attach to process macro")
            End Select
        Catch ex As System.Exception
            MsgBox("Unhandled exception occurred: " & ex.Message)
        End Try

    End Sub
    Private Sub ShowMessage(ByVal message As String)
        Call MsgBox(message, MsgBoxStyle.Exclamation, "Attach to process macro")
    End Sub

End Class

Friday, 16 May 2014

Unshelving just the items you want in VS2013

Say you have a large shelve set and you only want to unshelve certain file types from that shelve set, like the project references changes you've made.

  1. Find your shelve set
  2. Open it in VS2013
  3. In the filter box type *.csproj
  4. Select all in the results and then right click
  5. Choose Exclude unselected from the context menu
  6. Unshelve the resulting items, which should just be the csproj files.

Using Git with Codeplex


Using Git with CodePlex

Git is a distributed version control system that is popular for open source projects. To learn more about how to use Git, the Pro Git site is a great reference. The following is a step-by-step guide to get started using Git for your CodePlex projects.

Step 1: Create your CodePlex project

Log-in to CodePlex and create a project. When selecting the source control, pick Git.


Once your project is created, click on the Source Control tab. Click the “Clone” action link to bring up connection details:


The clone URL is already selected and you can just type ctrl-C to copy the URL. We’ll be using this later.

Step 2: Set up Git

Download and install the latest Git tools for your operating system:

For the remainder of the guide, we’ll assume that you’re on a Windows system for screenshots.

After you’ve installed Git, you’ll want to provide Git with a username. Git uses this information to keep track of commit history, and CodePlex uses this to match commit history with CodePlex users. To do so, open the Git command line (Git Bash if you chose the default installation options for Git on Windows) and type the following command:

git config --global "CodePlexUsername"


Step 3: Clone the repository

Next, you’ll want to set up your repository on your local machine by cloning the repository on CodePlex. In the Git command line, change the directory to a folder where you want to store the source code of your project and then type the following git command:

git clone https://CloneUrl NameOfFolder

where CloneUrl is the Clone URL you noted in Step 1, and NameOfFolder is the name of the folder where you want the source code to be stored. For example:

git clone PlastikDreamGit


Since you haven’t yet published your project, you’ll have to enter your CodePlex username and password. Because your repository is empty, you’ll get a warning message, but that’s fine.

Step 4: Push to CodePlex

Go to your newly created directory, and add your source code. Stage your changes using git add. For example, let’s say you add a readme file to your directory:

cd PlastikDreamGit

notepad readme.txt

git add readme.txt


Commit your changes with a commit message:

git commit -m "my first commit to CodePlex”


Push your changes back up to CodePlex.

git push origin master

Type in your CodePlex username and password when prompted.


Visit your source code history on the project page and verify that your changes have been pushed by browsing to the source code tab.


Thursday, 15 May 2014

Clip.exe and other sysinternals tools


Some brilliant little utilities talked about on the sysinternals session from MS TechEd 2014 here

Also check out which has integration into the latest version of sysinternals process explorer. Latest version can be downloaded from Virus total is a good way of using multiple virus scanners rather than just one to check files that you aren't sure about.


Had never heard of clip.exe before… (built into windows by default as well).

C:\Dev\RussellReynolds2010\Main\Solutions\Scripts>clip /?



Redirects output of command line tools to the Windows clipboard.

This text output can then be pasted into other programs.

Parameter List:

/? Displays this help message.


DIR | CLIP Places a copy of the current directory

listing into the Windows clipboard.

CLIP < README.TXT Places a copy of the text from readme.txt

on to the Windows clipboard.

More useful tools are:

  1. DU.exe - disk usage check : e.g.
    du -ct | clip.exe
  2. RU.exe - registry usage check : e.g.
    ru -ct -l 3 "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node"


Friday, 2 May 2014

WPF binding to static property

Just so I don't forget again, here's how it's done...



        <ValueConverters:BooleanToVisibilityConverter2 x:Key="booleanToVisibilityConverter2" />



<StackPanel x:Name="MyStackPanel"
            Visibility="{Binding Source={x:Static Services:UserPreferencesService.Instance}, Path=UseWebAssignment, Converter={StaticResource booleanToVisibilityConverter2}, ConverterParameter=true}">

How to Fix a Humax HDR FOX T2 PVR that will not stay powered on

Issue When you attempt to power on your Humax the standby orange light goes blue for a moment, and then powers off automatically again. ...