Debugging “Just My Code”

December 5, 2009 – 16:59

Within EVEMon we have started making heavy use of LINQBridge which uses Visual Studio 2008′s Multi-Targeting capabilities to allow a .NET 2.0 applications to use the compiler functionality of C# 3.0. This reduces our need to push EVEMon towards .NET 3.5, and simplifies our dependency stack for the end user (.NET 2.0 is pre-installed on Vista and above, .NET 3.5 is pre-installed in Windows 7 and above).

One of the annoyances I have run into is every time there is a problem with a LINQ statement the debugger will stop in the LINQBridge project rather than EVEMon’s code; this usually tells you nothing useful forcing you to dig into the exception to find the stack trace to find out which line caused the exception.

I found a natty attribute in DebuggerNonUserCode that allows you to tell the debugger to treat a class as Non-User Code:

[System.Diagnostics.DebuggerNonUserCode]

So far, I have not found a disadvantage in doing this. I am being conservative with my use in case I find some glaring problem, however LINQBridge has proven a stable project, and quite frankly I would much rather be looking at my own broken code when something goes wrong, rather than LINQBridges working code.

Controling Code Outlining with the Keyboard

November 3, 2009 – 20:13

Code outlining is a feature of supported by Visual Studio and many other editors, MSDN has some good documentation for VS2005, VS2008 and VS2010. If I were asked to explain this as briefly as possible, I would probably say:

Code Outlining is the logical partitioning of code in such a way that the user interface, or editor, is able to selectively hide the body of the content (such as a class, struct, enum or method) whilst leaving the signature or some identifying comment visible.

You can see this in action in Visual Studio 2008 with the following Screenshot:

CodeOutliningVS2008

I accidentally turned off Code Outlining today by hitting some keyboard shortcut that I didn’t know how to reverse, this lead me to discover several useful keyboard shortcuts for managing the display of your code from the keyboard.

As it turns out I managed to hit Ctrl-M followed by Ctrl-P (or just P in fact) which maps to Edit.StopOutlining, by default it seems that the Visual C# 2005 mapping scheme doesn’t provide a shortcut to enable Automatic Outlining so instead you can access the command through Edit Menu -> Outlining -> Start Automatic Outlining.

Enabled again, I get to play with code outlining from the keyboard:

  • To toggle (collapse an expanded block or expand a collapsed block) the closest outlined element use Ctrl-M followed by Ctrl-M.
  • To toggle everything use Ctrl-M followed by Ctrl-L (I find little use for this)
  • To collapse to definitions use Ctrl-M followed by Ctrl-O

The last one is the most useful when used in conjunction with Regions as after colapsing to definitions you will get something similar to this:

ColapseToDefinitionsVS2008

You might have noticed in the first screenshot that CodeRush Xpress adds a coloured line between the beginning and end of blocks of code, this is a nice feature if you have long blocks of code, which of course you shouldn’t have.

CodeRushXpressBlockLines

There we go, an errant key stroke can lead to learning and blogging, who would have thought it?

Card Reader on Acer Aspire 5100 Series Under Windows 7

October 26, 2009 – 21:24

Update (15/11/2010): the drivers listed in this post are out of date and may cause a BSOD, several alternatives are listed in the comments; however Microsoft appear to have approved 64-bit drivers on Windows Update.

I am typing this on my Acer Aspire 5102WLMi which is one of the popular (if flawed) Acer Aspire 5100 series; I rescued this one from the Balconi Test by putting a bit of rubber (it was a cut down rubber foot) on top of the South Bridge chip set, that however is not the story I am telling today.

I never bothered to install the Card Reader driver on this laptop while I was running the Windows 7 Beta, mainly because I am lazy, but also I didn’t have a need for it so it never came up. With the release of Windows 7 I wanted to get the system perfect, seeing as hopefully it will last a good year in it’s present state, and I wanted to be able to re-arrange the SD card from my Acer PDA.

Windows 7 x64 was unable to identify a driver for this particular card reader, this left me with three unknown devices in Device Manager:

Missing Drivers Acer 5100

The Acer website was a bust, as far as Acer are concerned this laptop won’t even run Vista x64, so I had to dig deeper. From past experience of looking for drivers without using Windows Update I knew that I could probably identify the manufacturer from the Hardware and Device ID’s available through Device Manager. If you want to follow along here are the steps:

  1. Open up Device Manager (Right Click “Computer”, Choose “Manage”, Select “Device Manager”)
  2. Identify your unknown devices (They will look similar to the image above, although the text will differ)
  3. Right click one of them and select “Properties”
  4. Switch to the “Details” tab
  5. Change the property drop down box to read “Hardware Ids”

What that will give you is one or more strings looking something like this

PCI\VEN_1524&DEV_0530&SUBSYS_009F1025&REV_01

I have marked the two important parts in bold, the four digits after “VEN_” tell you the PCI Vendor number, the four digits after “DEV_” tells you device number these two numbers should uniquely identify the driver.

There are several sites that allow you to lookup these numbers, I tend to use the publicly available PCI Vendor and Device Lists at PCIDatabase.com. Which has always given me good results with minimum fuss and adverts.

Armed with the above I identified the manufacturer of the Card Reader was ENE Technologies, sometimes this is all you need to find the driver. You can Google/Bing the name and click the download or support links and get the latest drivers. This isn’t always the way, as some OEMs don’t offer drivers leaving that down to the system integrator to offer that service.

So some time with Bing, I found some drivers for various ENE Devices, however the drivers available from VersionTracker seemed promising. After downloading and unzipping the contents of the file to a folder on my Desktop, I was able to point Device Manager at these files for each of the unknown devices I was left with three working devices and a fully operational Card Reader.

ENECardReaderDriversAcer5100

Hope this helps some other people with similar laptops or Card Readers, post in the comments with your experiences, please include the manufacturer and model of the laptop/netbook you have succeeded with and hopefully you will help someone else with the same devices.

Change your MTU under Vista, Windows 7 or Windows 8

October 23, 2009 – 21:11

I have been updating this blog post over the years since I first discovered the issue with my computer in Windows Vista, now I am on Windows 8 and also on FTTC broadband; Path MTU Discovery seems to just work. I have tested the process so the approach and the commands still work in Windows 8, I however no longer need to use this process personally.

For some reason that has escaped me Path MTU Discovery (PMTUD) in Windows just doesn’t seem to figure out the MTU for a given path (something to do with routers being poorly configured to not respond to ICMP requests). So Windows uses the default. For the most part this doesn’t affect anyone, however if it does affect you, it really annoys you. Failure of PMTUD will result in some websites not loading correctly, having trouble connecting to normally reliable online services and general Internet weirdness.

The resolution is to set your default MTU to one lower than the Ethernet default of 1500. Here is how:

Step 1: Find your MTU

From an elevated Command Prompt in Vista/Windows 7 or the same elevated Command Prompt in Windows 8 enter the following command:

netsh interface ipv4 show subinterfaces

You should get something like this

MTU         MediaSenseState  Bytes In    Bytes Out  Interface
----------  ---------------  ---------   ---------  -------------
4294967295  1                0           13487914   Loopback Pseudo-Interface 1
1500        1                3734493902  282497358  Local Area Connection

If you are using Ethernet cable you will be looking for “Local Area Connection” or “Ethernet”. If you are using Wireless you will be looking for “Wireless Network Connection”. The MTU is in the first column.

Step 2: Find out what it should be

In the Command Prompt type:

ping www.cantreachthissite.com -f -l 1472

The host name should be a site you can not reach, -f marks the packet as one that should not be fragmented the -l 1472 sets the size of the packet (1472 = Ethernet Default MTU – Packet Header, where the Ethernet Default MTU is 1500 and the Packet Header is 28 bytes)

If the packet can’t be sent because it would need to be fragmented you will get something similar to this:

Packet needs to be fragmented but DF set.

Keep trying lower packet sizes by 10 (i.e. -l 1460, 1450, 1440, etc.) until you get a successful ping request. Raise your packet sizes by one until you get a “Packet needs to be fragmented but DF set.”. The last successful value plus 28 will be your MTU value.

In my case a packet size of 1430 succeeds but 1431 fails, so 1430 + 28 = 1458.

Step 3: Set your MTU

Now you have identified the interface you need to change and the ideal MTU for you, now it is time to make the change. Again from an elevated Command Prompt type the following replacing my MTU of 1458 with your own value:

netsh interface ipv4 set subinterface "Local Area Connection" mtu=1458 store=persistent

Or if you are using a Wireless connection:

netsh interface ipv4 set subinterface "Wireless Network Connection" mtu=1458 store=persistent

If all has gone well you should have a perfectly working internet connection.

Music to Install Windows By

October 22, 2009 – 21:12

Windows 7 Home PremiumWindows 7 turned up in the post today. The red box is Visual Studio 2008 which is there to show that the boxes have a similar profile to the old style hard cases.

I have been running the Beta since it was first available to the general public, and I have had Windows 7 Business at work for a couple of weeks now. Bought Windows 7 Home Premium for about £45 from Tesco. One copy for the main PC which I will probably re-build at Christmas and one copy for the laptop which is re-built now. Scott Hanselman described Vista as an operating system that stabs you in the eye a thousand different ways, I would have to agree with that. Windows 7 is different, things work how you think they should and don’t seem to randomly break when you least expect it.

As for the title of this blog post, I have mostly been installing Windows 7 to Vampire Weekend which Kev introduced me to. The track M79 seems to have taken some inspiration from the Sailor’s Hornpipe better known as the Blue Peter theme tune, seems to cut off just at the moment I am expecting it to carry on into the main part of the music. Maybe there is a Mike Oldfield link in addition to the lyrical Peter Gabriel link.

If I am moved to over the course of the next couple of week I shall try and point out some of the new features available in Windows 7 that are cool. For the time being try the following hold down Alt, while still holding down Alt press “Alt Gr” (The other side of the space bar) then press Tab. For some reason you get the old XP style Alt-Tab window. Utterly pointless?

Adjusting Selections in CodeRush Xpress

October 16, 2009 – 20:30

I found this function totally accidentally when I knocked my mouse into a key when something interesting popped up on Twitter. I happened to have a variable selected like so:

Variable Selected in Visual Studio

The key that I knocked was the Number Pad “+” key, and it expanded the selection like this:

VariableSelectedPlus1

As any self respecting Systems Administrator would do I wondered if doing exactly the same thing repeatedly would have equal or compound effects.

VariableSelectedAgainAgain

Strangely enough it worked, the selection will continue to expand selecting increasingly larger sections of code. The reverse works as well if you press the Number Pad “-” key the selection will be reduced.

WhatHappened

As I was looking for documentation on this function; I found that you could use the CamelCase select function to start selections off using Ctrl+Shift+Left (or Ctrl+Shift+Right) this will take your selection from the current cursor position to the next upper case character to the left (or right). This can be coupled with the Number Pad “+” to expand your selection from a variable to an expression, to a line then a block. Neat!

Each of these discoveries was announced with a handy little popup in the bottom right hand corner of the viewport telling me what happened, and if relevant what function was suppressed.

I am going to make a concerted effort to spend my lunch break watching some more videos on DevExpress’ training site. I got 10 minutes today and watched what appeared to be footage from a launch event or a conference which was interesting but didn’t really teach me anything specifically.

Find Files in CodeRush Xpress

October 12, 2009 – 13:27

As I mentioned in my previous entry I have started using DevExpress’s CodeRush Xpress. It is a free cut down version of CodeRush that I heard about in an episode of .NET Rocks. I have wanted add something to my Visual Studio development experience and I can’t justify the cost of either Resharper or CodeRush at the moment. There has been quite a bit of discussion about Resharper vs. CodeRush and in my experience most people I have spoken to love one and hate the other.

I hope to be able to write a series of posts about some of the features found in CodeRush Xpress which I hope will clarify their purpose and use in my mind and maybe help someone find the function they are looking for.

QuickFileNavigationAbouFirst off “Quick File Navigation”, this is a search function for locating a file by file name, I am finding it increasingly useful when looking through patches as it allows me to very quickly jump to a file name. Particularly as I am trying to move my projects to a one class per file so if I can remember the class name I can find the code file very quickly.

The “Quick File Navigation” dialog is accessible through the keyboard short cut Ctrl+Alt+F. Typing will filter the list box by the name of the file matching anywhere in the filename including the extension.

An additional feature for those who like me use CamelCase in their file names; if you enter your filter terms in capital letters it will search for capitalized words, in order within file names. Thus entering “AW” into the search box will also bring up the AboutWindow.cs in the above solution.

Combining the above with the Ctrl-G keyboard shortcut in Visual Studio 2008 to go to a specific line we can do the following to go to line 162 in ShipLoadoutSelectWindow.cs:

Ctrl+Alt+F  →  S,L,S,W  →  Ctrl+G →  1,6,2

DevExpress have a great training video on their tv.devexpress.com sub site.

Ctrl+Alt+F → S,L,S,W → Ctrl+G → 1,6,2

Long time no blog…

October 10, 2009 – 13:21

I had been intending to post up all sorts of bits of news about life, driving, programming and cats but it didn’t happen. I have been busy which is good, however it doesn’t leave very much room for blogging. This post is going to be one really quick catch up entry to try and get me back into the swing of it.

I finally passed my driving test at the beginning of the summer, it was my fourth try and I passed with three minors which was a great feeling… since then I have driven once, as part of PassPlus, which didn’t really feel vastly different, although it was more enjoyable knowing that I didn’t have a test coming up. Catherine and I have decided to wait for a bit before we get a car so we can assess what Catherine will need in terms of model and adaptations in a car to allow her to get the most out of it.

Zoe and KerrySadly Kerry, Zoe’s sister died a few months after Zoe, as a family we weren’t ready to lose her, although it wouldn’t have been fair to let her suffer an operation that might not help anyway, so my parents decided it was best to have her put down. My brother and I got a chance to say good bye to her, she wasn’t her normal self and was in a lot of pain. We are all very sad.

In programming land I spent last weekend learning SQL Server Integration Services and this weekend I plan to get into Analysis Services. Have been doing some utility programming at work to automate some of the file server operations we do, I am trying to automate as much as possible using something similar to duck tape programming to free me up to do more programming to create a more unified and friendly framework for managing the school network. Started using CodeRush Xpress both at home and at work.

In sys. admin world I have been continuing to use and learn Windows 7, I now have RTM installed at work still waiting for RTM to arrive at home on or around the 22nd. Been reading and listening to various resources surrounding Windows 2008 R2 particularly some excellent podcasts on RunAs radio.

Running through the rain

May 5, 2009 – 20:04

I don’t send on these Internet “chain letters”, as in general I don’t think people want to get generic forwarded and forwarded e-mails from me, they would probably prefer me just to e-mail them to ask them a question, favor or just to say hello. I do like this one though, it has a fair point and it makes it well. I have removed what I suppose would be described as the postamble from the bottom, as it doesn’t work for blog  posts.

A little girl had been shopping with her Mom in Checkers. (For those that do not know Checkers is a Supermarket store in S.A.) She must have been 6 years old, this beautiful red haired, freckle faced image of innocence. It was pouring outside. The kind of rain that gushes over the top of rain gutters, so much in a hurry to hit the earth it has no time to flow down the spout. We all stood there under the awning and just inside the door of Checkers.

We waited, some patiently, others irritated because nature messed up their hurried day. I am always mesmerized by rainfall. I got lost in the sound and sight of the heavens washing away the dirt and dust of the world. Memories of running, splashing so carefree as a child came pouring in as a welcome reprieve from the worries of my day. The little voice was so sweet as it broke the hypnotic trance we were all caught in “Mom, let’s run through the rain,” she said. “Let’s run through the rain!” She repeated. “No, honey. We’ll wait until it slows down a bit,” Mom replied.

This young child waited about another minute and repeated: “Mom, let’s run through the rain,” “We’ll get soaked if we do,” Mom said. “No, we won’t, Mom. That’s not what you said this morning,” the young girl said as she tugged at her Mom’s arm. “This morning? When did I say we could run through the rain and not get wet?”

“Don’t you remember? When you were talking to Daddy about his cancer, you said, ‘If God can get us through this, he can get us through anything!” The entire crowd stopped dead silent. I swear you couldn’t hear anything but the rain. We all stood silently. No one came or left in the next few minutes.

Mom paused and thought for a moment about what she would say. Now some would laugh it off and scold her for being silly. Some might even ignore what was said. But this was a moment of affirmation in a young child’s life. A time when innocent trust can be nurtured so that it will bloom into faith.

“Honey, you are absolutely right. Let’s run through the rain. If GOD let’s us get wet, well maybe we just needed washing,” Mom said. Then off they ran. We all stood watching, smiling and laughing as they darted past the cars and yes, through the puddles. They held their shopping bags over their heads just in case. They got soaked. But they were followed by a few who screamed and laughed like children all the way to their cars.

And yes, I did. I ran. I got wet. I needed washing.

Circumstances or people can take away your material possessions, they can take away your money, and they can take away your health. But no one can ever take away your precious memories… So, don’t forget to make time and take the opportunities to make memories everyday. To everything there is a season and a time to every purpose under heaven.

I think it was the penultimate paragraph that made me think the most, all Christians have had that “saving” experience, but we need washing clean every morning because our acts and experiences don’t match up with God’s expectations.

New Webhost

May 3, 2009 – 17:13

I have transfered to a new web-host, if you are seeing this message it has worked. That is all I have to say about it.