Fix for XAML Highlighting in VS2010

Both Visual Studio 2008 and 2010 have a rather annoying issue relating to how XAML is highlighted in the Text Editor. I’ve complained in the past that the XAML designer team introduced a separate set of classifications (i.e. options in the Fonts and Colors dialog) to configure how XAML code would be highlighted by the editor, when in fact, it is just, for the most part XML and it would’ve been used if the XAML editor just used the same color definitions used by the XML editor.

However, this isn’t 100% true. It turns out that the XAML code editor uses the colors and font settings configured for String (e.g. like a C# string) to render raw text inside an XML element in the XAML code. Normally, this isn’t too much of a problem, until you create a color scheme that uses a custom background color to highlight strings. Then, this is what you end up with in XAML:

Xaml_Before

Notice how the different background is used to render even spaces used for indentation, which looks very, very ugly.

Now, there’s nothing I can do about VS2008, but at least with VS2010, I was able to write an extension that fixes this problem. Here’s how it looks with the extension enabled:

Xaml_After

Much better, right?

Here’s basically all the code needed to fix this:


[Export(typeof(IWpfTextViewCreationListener))]
[ContentType("XAML")]
[Name("XAML Fix")]
[TextViewRole(PredefinedTextViewRoles.Document)]
public class XamlFixCreationListener : IWpfTextViewCreationListener {
   [Import]
      IClassificationTypeRegistryService registry = null;
   [Import]
      IClassificationFormatMapService mapService = null;

   public void TextViewCreated(IWpfTextView textView) {
      var formatMap = mapService.GetClassificationFormatMap(textView);
      var textClassification = registry.GetClassificationType("text");
      var stringClassification = registry.GetClassificationType("string");
      var props = formatMap.GetExplicitTextProperties(textClassification);
      formatMap.SetExplicitTextProperties(stringClassification, props);
   }
}

As usual, you can get the code for the extension from github. Enjoy!

Attach/Detach VHD

Windows 7 has some nice and very welcome functionality for attaching/detaching VHD files so that you can access files in them directly from the operating system, which is something I’ve been finding very useful when working out of my laptop. Unfortunately, it’s a bit of a drag to have to go through disk manager every time I want to use one of my VHD files.

I started looking for a way to do this from the command line and discovered that diskpart.exe can do it, but the syntax is more than I can usually remember, so I just wrote these two quick PowerShell functions:

function add-vhd($vhdfile) {
   $path = resolve-path $vhdfile
   $script = "SELECT VDISK FILE=`"$path`"`r`nATTACH VDISK"
   $script | diskpart
}
function remove-vhd($vhdfile) {
   $path = resolve-path $vhdfile
   $script = "SELECT VDISK FILE=`"$path`"`r`nDETACH VDISK"
   $script | diskpart
}

Visual Studio 2010 RC

Following the release of Visual Studio 2010 Release Candidate, I installed it on one of my laptops. I ran into some minor issues with the Silverlight dev tools SDK, but I hear they’ve been resolved for RTM. Other than that, it seems to be working fine.

I’ve already updated my Current Line Highlighting and Keyword Classifier extensions for the RC, so they should be ready to go if you build them from source.

vs2010

Minor Update to PowerShell Syntax for Vim

Jeffrey Knight was kind enough to point out a small missing thing in the expressions for built-in variables in my modified syntax file for PowerShell scripts for Vim. I’ve now updated the syntax file in my github repository following Jeffrey’s suggestion and also fixed another related issue while at it.

Thanks Jeffrey!

Essential BizTalk Debugging Skills

On the topic of debugging skills, there are many things said and to be said, but I thought I’d take a moment to reflect on a few skills I believe BizTalk developers should develop to solve problems on their solutions effectively (in no particular order):

  1. Trace the execution of BizTalk processes end-to-end, covering both messaging and orchestrations. While this seems obvious at first, it can be tough on complex solutions that rely heavily on pub/sub and direct binding!
  2. Discovering the reasons why a service instance might be getting suspended. In particular, quickly finding any possible exception information coming from faulted instances.
  3. Using the orchestration debugger to figure out where a given Orchestration instance is getting suspended.
  4. Matching any receive shapes in an orchestration to the origin of messages coming for it. This might require matching logical ports with physical ports as well as possible direct-binding sources of messages.
  5. Tracking possible reasons for routing failures, particularly when correlations are involved. This includes being able to understand routing failure reports, checking the state of any required promoted property, comparing subscription information either directly on the message box as well as from reading orchestration code, and so on.
  6. Detecting and solving situations that stop flow/processing of messages, related to thread pool issues or thread starvation.
  7. Detecting zombie message instances and their possible consequences.
  8. Knowing how to enable the BAM tracing infrastructure to debug and solve issues with BAM not writing data to the BAM primary import database.
  9. Using the Visual Studio Debugger or WinDBG to debug BizTalk processes. This includes figuring out the right processes to attach to!
  10. Debugging assembly-loading/versioning issues. This includes how to use Fuslogvw.exe and friends.

Anyone else has any other ideas?

Upgrading to Karmic Koala and Bugs

Yesterday afternoon I kicked off the update to Karmic Koala (9.10) on my trusty Dell Latitude D820 laptop that was running Ubuntu 9.04. The update took a long time (mostly due to the servers getting hammered) and, overall, worked just fine.

I did have to struggle with a couple of things. For example, I originally installed that machine with Xubuntu a long time ago and then converted to GNome. The Karmic upgrade enabled Xubuntu as the default again and configured XFCE as the default session, but that’s easy enough to fix. I can’t seem to find where to change my logon screen to the one I was using, though.

The big issue issues I’m running on, however, are related to what I use my machine the most for :( :

  • I had to change some of my scripts for mounting Windows shares in other machines as specifying the rw option to mount was no longer working. No errors, just mounting read-only instead. To fix this, I had to add the file_mode=0777 and dir_mode=0777 options to the mount command. No big deal, but took me a few Google searches to figure it out.
  • Building C/C++ apps/libraries on a samba share doesn’t work anymore, as GCC will always fail with a “Value too large for the defined data type” error. I’m basically hitting the bug described in this bug report. I do hope it gets fixed soon, as otherwise I will have to get back to 9.04, which does work fine. Meanwhile, I’ll try setting up another VM with 9.04 to see if I can get some work done. Ouch!

Windows Virtual PC and ClearType

After repaving my desktop machine (which is my main work machine) with Windows 7, I tried the Windows Virtual PC for Windows 7 RC to run the few Virtual PC-based Virtual Machines I still use occasionally. It worked, though I didn’t bother installing the updated integration components (formerly known as Virtual Machine Guest Additions) for a while which caused a number of issues.

This week I took a bit of time to uninstall the RC and install the RTM version of Windows Virtual PC. Notice that I have no interest in XP mode, merely in running my existing VMs, many of which are running Windows Server 2003.

A couple of things worth pointing out from this sad experience:

  • Updating Virtual PC from the RC to RTM took me 4 reboots. Seriously screwed up in this day and age, but I fully blame it on…
  • The ungodly bad UI that Windows Virtual PC uses. The old Virtual PC console was a bad UI, but getting rid of it and replacing it with a shell extension, and one that forces you to keep your virtual machine definition files in a specific folder and has terrible usability was an incredibly stupid choice. No wonder so many reboots are needed for any updates, since Windows Explorer will get in the way.
  • After updating the integration components on my Windows Server 2003 virtual machines, imagine my surprise at seeing: (a) virtual pc locking the VM and wanting me to log in pretty often, (b) no way to change VM resolution from inside the VM and without ClearType being used to render fonts at all.

And then I remembered what causes this: Windows Virtual PC sort of ditches the old display rendering and instead will use RDP to access your VM (so you’re pretty much working in a sort of embedded RDP client). Windows Server 2003 didn’t support ClearType over RDP originally, so I went hunting for KB946633 and install it on my VM. One more restart, and ClearType was enabled.

This is supposed to be progress, ladies and gentlemen.

Some Comments on Visual Studio 2010 Beta 2

I’ve been fooling around a bit with the new Beta 2 build of Visual Studio 2010, so I’d thought I’d share a few comments about my general experience with the IDE, focusing mostly on the code editor.

What I like

  • After fooling around with my Windows configuration, font rendering on beta 2 looks a bit better than it used to do in beta 1, which is great. It’s now on par with VS2008, I’d say (and zoomed text looks awesome). The only exception here is the rendering of line numbers, which is pretty bad, for whatever reason.
  • One of the issues I had commented earlier about background color handling in the editor seems to have been improved. Not sure how well it will work in practice, but the new behavior seems a lot better and more useful. Here’s a quick look at how the same line looks like normally, with a breakpoint and as the current statement:

    EditorBg

  • You can now change the colors used when highlighting a collapsible region so that it doesn’t screw up with your custom color scheme. I still find the feature fairly useless, though, but maybe it’s just me.
  • Easy horizontal splitting of code windows is back. Yay!

    VSSplit

  • The IDE seems a bit more stable (beta 1 was pretty bad). I haven’t had any bad crashes yet. If you’re writing Visual Studio Extensions, though, be aware that VS handling of exceptions thrown by extensions (particularly editor-related ones) is still absolutely awful. It will crash, and it will do so badly. You might get a fairly useless dialog box before the crash, if you’re lucky.
  • Vertical Selection is back. Sorely needed. The Insert-In-Vertical-Selection bit is useful, but I’ve had that with ViEmu for years on previous VS versions. (By the way, there’s a slight bug in this feature in Beta 2: if you want to insert text at the start of multiple lines, you need to block-select the first char, type in the new text and then fix the first chars of the lines that you overwrote. If you make instead an empty vertical selection first, insertion will go very wrong).
  • The new C# signature help tooltips are pretty nice. They contain useful information, and they look pretty good. They are very much easier to read than the old VS2008 tooltips.

    Tooltips 

    I do have one complain here, and it’s the lack of consistency: These nice tooltips only appear if you use the Intellisense –> Parameter Info command (usually bound to Ctrl + Shift + Space). If you just hover the mouse over a method, you get a tooltip with the same info, but without all the nice formatting (looking very much like the VS2008 ones, just maybe in a different color).

    But it goes a bit beyond that. For example, those uglier tooltips use fixed-with fonts for all the text. One more inconsistency is that the tooltips shown when a member is selected in the IntelliSense completion list dropdown have the almost the same contents as the other two cases, but this time rendered in a proportional font instead. At least be consistent about it in all places! It would be awesome if all of them used the really nice thing the new formatted tooltips do: render the description text was in a proportional font and leave the signature in a monospaced font.

What I don’t like so much

  • Editor Performance: When it comes to actually editing text, the editor is still not very fast. It’s a bit better in some spots than beta 1, and in general redrawing of the screen is fairly good, though I still see a very, very slight delay when typing text fast.

    Part of the problem here is that I’m running VS2010 on a Virtual Machine (and one running Win7 at that, which isn’t exactly snappy). Without hardware acceleration, the WPF-based text editor doesn’t quite perform as well as one would like. On the other hand, this is pretty much the standard setup for a lot of developers out there, so just ignoring this isn’t really an option for lots of us (not sure if it’s something MS cares about, though).

    The part where performance is pretty bad, in my specific experience, is scrolling: Right now, scrolling in the editor is absolutely awful. It is very slow, regardless of whether you are scrolling by simply moving around with the caret or using the scrollbar. Really hope this gets fixed.

    As an aside: I did try running VS2010 through RDP (terminal services). The experience was pretty much the same: It works reasonably OK as long as you have a large enough bandwidth between the two machines to enable all the graphics features (particularly ClearType, without which the editor is not as nice). Scrolling still sucks the big one over RDP. For more restricted connections, I’m not sure yet usable the editor will be.

  • Italics: Still not there. Seriously screwed up that we’ll have to wait another 3 years to get one stupid checkbox added to the Fonts & Colors option dialog to enable italics fonts on our configurations. The text editor itself does fully support italics and they look beautiful; you just have to hack your way around it to enable them (or use extensions that forces part of the text to render as italics). Not a happy panda about this.

One More Update to KeywordClassifier

I’ve just committed some updates changes to my KeywordClassifier extension for Visual Studio 2010 Beta 2.

I had already worked around some problems my custom classifier was causing with Beta 2 related to it’s use of a recursive invocation of the classifier services, but @noahsmark proposed a better way to get this done in Beta 2 that would simplify the code a bit and get rid of the need to do the recursive invocation in the first place. This involved switching away from a custom classifier and instead implementing a custom ITagger<ClassificationTag> service instead.

The end result (to the user) is the same, but the code is definitely cleaner! In retrospect, though, naming the extension “KeywordClassifier” might not have been the best choice :) .

LineAdornment Extension Fixed For Beta 2

I’ve now fixed all remaining issues with my Current Line Highlighting extension for Visual Studio 2010. Besides fixing all build issues, I started running into issues where IWpfTextViewLineCollection.GetMarkerGeometry() was returning null when the text snapshot was empty (like an empty line).

I reworked the code to avoid this call and instead manually create a new geometry directly out of the line bounds (which I would always do anyway to adjust the margins). This seems to work pretty well for now. Here’s a screenshot of how it looks like on the new build:

LineExt

As usual, the updated code can be found in the GitHub repository.

←Older