Tuesday, October 13, 2015

Quick Fix: You can't debug the Silverlight application because the Silverlight Developer Runtime is missing

You've fired up the shiny new Visual Studio 2015 (or an older version) to debug a Silverlight 5 application and you get an error: "You need to install the latest silverlight developer runtime before opening silverlight project". And in matters requiring a blog post, the go.microsoft.com link provided doesn't go anywhere.
Microsoft, intelligently, gave up on Silverlight but there are still many projects that require it. My day job is Lync development and I needed this to troubleshoot a Lync CWE. All variations of the runtime are still available, but due to a security issue, they were moved to an obscure place... a security bulletin!
What you want is KB2847559. Click the install link and you'll see Silverlight_Developer_Runtime.exe as an option. Be sure to uninstall Silverlight first, or you'll get an error. The 64-bit variant is there as well, along with the Version 5.0 SDK and others.
Woo Hoo! Time to party like it's 2011!
And in case you're looking for the Toolkit, it's still at its old CodePlex link.

Sunday, September 13, 2015

HOWTO: Fix a GE XL44 Gas Oven that won't pre-heat (or takes forever to pre-heat)

You're messing with a gas oven. Natural gas is dangerous. Electricity is dangerous. You could break your oven. You could burn or kill yourself. If you're not comfortable with fooling around with these sorts of things, call a professional. I'm not a professional, I'm a homeowner who likes to tinker. This information is provided AS IS with no warranty express or implied. If you use any of this information to repair your stuff, YOU are responsible for the outcome and agree not to hold me responsible for it...even if the information I've provided here is dead wrong.
Repair Difficulty
Holy cow was this easy. Including taking apart, pulling the oven out of its spot, installing and putting it all back it took me 15 minutes to complete.
The problem can present itself as several different symptoms. In my case, the oven would take a long time to light and once it lit, it would shut off within a few seconds. I've had problems with this unit before and the symptom was that it wouldn't light at all. Because it was firing up but then shutting off, I had thought it might be the valve that was at fault, but after a lot of reading on the interwebs, I went after the igniter. When I tested the oven igniter, I noticed that it didn't glow nearly as yellow as the broiler igniter; that's a sure-fire sign of a failed igniter. It's a cheap part, available here: GE WB13K21 Igniter for Oven, and if it turns out that wasn't the bad part, rest assured, it'll fail at some point and it'll be good to have a replacement around. Be sure to search the exact model number of your oven (it's on a sticker that's visible when you open your warming drawer or oven door). Mine used the square igniter. Some use the round one.
What's wrong?
One word: Igniter. The igniter on these units has a lifetime, sometimes short, sometimes a few years. It depends on how often you use it, but it will fail. Most of the other parts on the oven will last a very long time. This one wont. Luckily, it's easy to replace.
Why is it doing this
Again, I'm not a professional, but I understand a little bit about how these things work. The process for starting your gas oven is pretty simple. Electricity runs through your igniter making it glow. In a working igniter, it will glow yellow/white and become *very* hot. When it reaches the right level of "hot", the valve that controls the flow of gas into the burner opens up. If for some reason the igniter isn't getting hot enough, the valve will not open. In my case, the igniter just beginning to fail. It was getting plenty hot (well past the point of being able to light the oven), but electrically it wasn't getting hot enough for the valve to keep gas flowing into the burner. As a result, within a second or so the valve would shut and the flame would die (and a small stench of natural gas would flow into the room).
Tools Needed
A 1/4" socket wrench or a screw driver that uses magnetic replaceable bits (common in "multi-screwdriver" tool sets -- they just happen to be 1/4").
A flat-head screw driver and a Phillips head screw driver (or appropriate bits for your magnetic replaceable head screwdriver).
Unplug the oven from power.
Shut the gas off leading to the oven.
Take the cover off of the bottom of the oven. This is done by removing the two screws in the back, pushing the bottom cover toward the back and tilting it up and out.

Take the warming drawer off by pulling it all the way out and then pushing up on the little plastic tab sticking out of the left side of the drawer arm and down on the right little plastic tab on the right.
You'll see the following in the back of your oven.
Unplug the plastic cable connection and pull the cable up from behind the igniter and burner in the back.
Remove the two screws securing the igniter.
OPTIONALLY - If you haven't purchased your part yet and just want to get the oven Bake feature working (we rarely use the broiler so we were more OK with that being out), you can swap the two igniters if they are identical in your XL44 (there are *many* models of XL44 on the market, so check them). If you decide to do this, remove the small metal panel from the back to get to the connection for the broiler igniter and remove the two screws securing it (Phillips head).
Install the new igniter. If you purchased one with a connection attached, just plug it back into where the other was.
Install the new igniter the same way the old one was installed, plug in the oven, re-open the gas valve and start a pre-heat. It should glow yellow:
Turn the oven off, let it cool, put it all back together and you're good to go!

Monday, August 31, 2015

HOWTO: Get the conditional compile symbols defined in the project for a source file (ITextView) in a Visual Studio Extension

One of the things I ran into when parsing with Roslyn in Stay Frosty was that #if / #endif blocks were treated as strictly in the parser as they are in Visual Studio (well, that should be obvious, it's the parser used by VS, isn't it?). That meant code that was riddled with preprocessor rules wasn't being parsed properly because it didn't know what I had defined.
Fortunately the Visual Studio SDK provides a way at these values. Unfortunately, it's not as straight forward as I would have liked.
Conditionals given an ITextView
Here's a quick extension method I whipped up to pull the "defines" out of the project file given an ITextView/IWpfTextView.
private static IEnumerable<string> Conditionals([NotNull] this ITextView textView)
            if (textView == null) throw new ArgumentNullException(nameof(textView));

            // Get the text document from the text buffer (if it has one)
            ITextDocument textDocument;
            if (textView.TextBuffer.Properties.TryGetProperty(typeof (ITextDocument), out textDocument))
                yield break;

            var componentModel = ServiceProvider.GlobalProvider.GetService(typeof(SComponentModel)) as IComponentModel;

            // Get the VsServiceProvider
            var vsServiceProvider = componentModel?.DefaultExportProvider?.GetExportedValue<SVsServiceProvider>();
            if (vsServiceProvider == null) yield break;

            // Get the DTE ...
            var dte = (DTE) vsServiceProvider.GetService(typeof (DTE));

            ProjectItem projectItem = dte.Solution.FindProjectItem(textDocument.FilePath);
            Configuration activeConfiguration = projectItem?.ContainingProject?.ConfigurationManager?.ActiveConfiguration;

            var defineConstants = activeConfiguration?.Properties?.Item("DefineConstants")?.Value as string;

            if (defineConstants == null)
                yield break;
            // DefineConstants entries are listed semicolon and comma delimiated, so we need to split on both.
            string[] constantSplit = defineConstants.Split(new[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var item in constantSplit)
                yield return item.Trim(); // They can contain whitespace on either end, so we'll strip 'em.
Of course, you could get some of those services via an Export and eliminate the GetService / GetExported value calls, but I thought I'd include them since I don't know what you've decided to get from MEF.
Have a lot of fun!

Sunday, August 30, 2015

Stay Frosty Visual Studio Extension - Method Block Highlighter, Text Clarity, Background Images and a lot more...

Updated 9/4/2015 9:00 PM Published to the Extension Gallery (links at the bottom). Thanks for the feedback!
For the most updated information, visit the release page

It's hard to believe but I've been working on this extension for almost a year. That's what happens when you only have a few hours every weekend and the occasional evening to work on a personal project. It started out with a simple desire to add a chiseled effect to the text displayed in Visual Studio. I used to get horrible migraine headaches and that little effect made text visibility at low contrast much better without having to change my syntax highlighting rules. A little later I decided I hated being tied to my multi-monitor setup just to be productive when writing software. So I started working exclusively from my laptop screen, a nice 1920x1080, but still not as nice as having a few portrait 1080P displays and a primary 2K, but with a little bit of a change in how I worked (mostly just getting used to some features I never had needed with unlimited real estate), I was easily as productive on my laptop screen. The advantages of changing scenes means I can work when I feel an inspiration; no more having to tuck myself into a room.
Most of the features of Frosty were designed with two purposes in mind: (1) Make working with code in limited screen real estate easier and (2) Make my environment prettier. Both are quite subjective and I don't expect everyone to agree with my decisions ... in fact, I wrote this for me, so if I'm the only user, I'll still be happy!
Method Blocks
Methods are highlighted with configurable colors, Static, Instance and Constructors. I decided against making those colors configurable in Fonts and Colors because I wanted to be able to control alpha on each, so I've done it via its own Options panel with a color picker. Sure, methods should be small enough to easily visually parse the beginning and end, but we're not always given the privilege of modifying code we've written. By default, constructors are bright, instance methods are dim and static methods are somewhere in between. I'm always looking to get back to a constructor, so I made it stand out a bit. In a God Object or a method that does too much (that, of course, *I* didn't write! :o) ...), finding important bits is easy.
Method Signatures
When the method signature scrolls off the top of the display, it shows up on the left hand side next to the box around the method. Sure, that's available from the drop-down at the top, but my caret isn't always in the method I want to know about. Now it's right in front of me.
Text Rendering
Text rendering in the editor window is also configurable. Much like the great extension, TextSharp, except I only apply the effect to the text editor window (no reason for this other than that I didn't need the rest). You can enable ClearType or kill it, along with other things WPF allows you to tweak that Visual Studio doesn't give you direct control over.
Chiseled Text Effect
It's off by default. This was the original feature that I wanted, but getting it working turned into a several month long adventure with HLSL. Unfortunately, it doesn't render properly in Visual Studio 2015 without Hardware Rendering enabled. The effect is touchy. Colors need to have a bit of grey in them to render and different colors render slightly higher or lower on the baseline. It's a bug I intend to fix, but for now consider it quite "alpha" in nature. That's life!
Go to "Stay Frosty" in "Tools|Options". You'll find it *highly* configurable. I like ultimate control over my environment so I tried to leave nothing out as far as customization. Maybe you don't like the features I've implemented? Turn 'em off or change them! Sure, software should be opinionated,... except when its users are developers.
I'm not ready to release the source code quite yet, but I will be. The extension is licensed under the Apache 2.0 license. I had to learn quite a bit about Visual Studio Extension development over the last few months and I'm hoping that my experiences with it will help others, so I'm separating out parts into their own projects that can be used by others as utility libraries. Right now, time is keeping me from completing that part, plus I'd like to get a little more feedback from testing in the wild before I throw that out there.
At the moment Frosty supports Visual Studio 2013 and Visual Studio 2015. I'm using the awesome NRefactory library for code parsing in Visual Studio 2013. The 2015 version, of course, uses Roslyn and as a result performs a bit better than the 2013 version. Since I started with 2013, I didn't want to abandon that work and all of the folks who are stuck on the old version.
Caveats - It's Beta
It's beta. If you run into difficulties, please let me know at matthew dot dippel at google's public e-mail service. I'd love to get it right and working. If you want to help out, I'll have the code out on GitHub soon!
There's (at least) one bug. The signatures don't always disappear from the left hand side when the top of the method becomes visible again when scrolling up. And it does use some additional resources when parsing code on Visual Studio 2013 -- it shouldn't get in the way too much on a decent machine (it performs well on my Core i5)
Updates from Initial Feedback
If you use ReSharper (I do!), you can enable their syntax highlighting rules (disabled by default, enable them in options).
You can now enable the Method Signatures to display regardless of whether or not the method signature is scrolled off screen (disabled by default).
Abstract methods are no longer bordered.
Two libraries were removed in favor of the PresentationFramework equivalents.
The error that some were seeing when visiting the options page might be fixed. (I'm not seeing this on my machines)
If ReSharper or the User Classes/Enums/etc Fonts and Colors option is missing, we'll use Identifiers instead of Plain Text.
Fixed an exception that occasionally happened on file load where the width of the adornment would be calculated to a negative number.
Fixed the caching of method signatures so they wouldn't have to be re-created every time they were drawn.

Download the Visual Studio 2015 Edition
Download the Visual Studio 2013 Edition

Wednesday, July 22, 2015

Quick Fix: Could not load file or assembly when instantiating XAML component (or IoC component) in a Visual Studio Extension Project

You're writing a Visual Studio extension that involves some XAML or IoC code that references a DLL file. When you attempt to instantiate the control, the debugger pops up with "Could not load file or assembly". You've checked the Fusion log and notice it isn't looking in the folder that contains the extension!
Add the attribute [ProvideBindingPath] to the class that represents the package (the class that implements the Package base class which is often completely empty).
Visual Studio's Extension engine usually figures out where your reference .dll's are and binds them easily, however, when a .dll is referenced in XAML or IoC, it isn't explicit enough for Visual Studio to handle proper binding. The ProvideBindingPath attribute tells the extension engine to look in the extension folder when attempting to resolve dependencies. In my case it was a fancy options page that used XAML for its UI rather than the automatically generated UI.