Sunday, January 29, 2012

Debug.Assert() – So, what about Release Mode?

Sometimes, as a developer, you create some little nifty tool to make life easier and you forget that other people may not have come up with that idea/solution and are still struggling with a problem you solved ages ago. 
I was having a Skype conversation with Pete Brown and he said “Why don't you blog this stuff, or set up a GitHub project or something with these things?”.  I told him, “well, actually, I just started blogging!”  
That conversation gave me a figurative kick in the tuchus, so I decided to share a small nugget.

Defensive Development

If you know me you know that I am a big fan of code instrumentation and “defensive development”. I think it’s the best way to protect yourself.  To me, developing defensively means that you are doing the following in your code:
Generally, you’re trying to “bullet-proof” your code.
Given that I think like this, I tend to use debug assertions a lot.

Saturday, January 28, 2012

My project featured as a Microsoft Case Study

It’s kind of neat seeing your own project featured as a Microsoft Case Study.

Of course, now I want to update it with more information, since a lot has happened since we gave them all that information.  The project has actually had a direct effect on the company’s quarterly profits and is now going to be rolled out internationally (in phases). 

Anyway, wanted to pause to toot my own horn for a sec.  Toot! Toot! Winking smile password idiocy

Back Story

I use Keepass to maintain all my passwords. Then, I have this password database stored in a USB key I carry with me.  I only have to remember one highly-entropic password (doesn’t mean it’s hard to remember, it just has to be hard to guess). So, I try to make my other passwords as complicated as possible.

Changing My Password on

Anyway, I went to change my password on live,com like I prefer to do on a semi-regular basis.  I got to their page and entered a new password.  I tried one that was 256 characters long, but I noticed that, with no warning at all, it truncated my password at 16 characters.
So, they have a minimum of 6 characters (which is on the page) and an apparent maximum of 16 characters.  So, I changed the options to generate a 16-character password with all sorts of variability in the characters used and I try again: (This time it was: “{jƒ/ýQîÔ·z4Ú«<[“)
Now, I get this lovely message:

What’s Missing?

Apparently, the powers that be at Microsoft ( aren’t going to bother telling me what characters are and are not allowed!  So, what?  I just sit here and guess for hours?
I was reminded of this great xkcd comic. This is not security!  It’s obscurity.  Making a person choose a password within 6-16 characters with a fixed subset of characters allowed just trims down the dataset that a computer needs to search while trying to crack the password. At the same time, requiring special characters (but not that special!) to be there in order to make it strong just makes it harder for humans to guess with the wonderful side effect of also making them nearly impossible to remember!
Well, I’m going to go keep trying passwords over and over again until I find one it will allow…ugh

Thursday, January 26, 2012

ASP.NET MVC OutputCache override

IE Strikes Again!

Because of my recent discovery of the IE9 “feature” that makes it cache unlike every other browser, I had to come up with a small change to our caching scheme on my project. To be fair, the IE9 team is actually well within RFC definitions of how to handle “cache-control: private”, so I shouldn’t complain too much about it. Though, why is it always IE that causes me to do extra coding?

Anyway, my solution was to add a “Default” OutputCache setting for all my MVC Controllers and then, to override these options on individual Controller Actions when needed.  The problem is: I can’t find any information on whether or not an OutputCache directive on an Action will override one on the Controller.

So, I wrote a quick test app to test it out. 

The Code

    // default everything to a tiny cache time
    public class HomeController : Controller
        public ActionResult Index()
            ViewBag.Message = "Welcome to ASP.NET MVC!";
            return View();

        // change to a longer cache time
        [OutputCache(CacheProfile = "LongCache")]
        public ActionResult About()
            return View();

Web.config mods

            <add duration="1" name="ShortCache" varybyparam="*">
            <add duration="60" name="LongCache" varybyparam="*">


Well, What do you know!? It worked! Hopefully someone else stumbles across this and saves themselves some time.

Monday, January 16, 2012

Silverlight 5 Toolkit, 3D and crappy installers..

   I'm in the rather grueling awesome process of tech reviewing my friend Pete Brown's new book, Silverlight 5 In Action.  As a part of that, I had to get setup with the Silverlight 5 Toolkit in order to get the new 3D templates. 

   Frankly, I'm rather excited at the prospect of playing around with 3D stuff in Silverlight.  We've come a very long way since the days of just displaying simple things like a clock in a browser plugin.

   So, I install the toolkit and start up Visual Studio 2010 and choose a Silverlight 3D Application


I called my project “Silverlight3dExample”.  Now, Visual Studio fires up the hamsters in their wheels and all the other rube goldberg-esque machinations inside and comes up with this lovely tandem of errors:



So, after a bit of googling, I realized, much to my chagrin, that I neglected a rather important notice on the screen of the Toolkit:

Note: You must install XNA Studio in order to use the new Silverlight 3D templates.Otherwise the new templates will not show up.

Oh.. uhh.. oops.  Seems kind of odd that such a big missing prerequisite isn’t also detected by the installer, but, whatever…

So, I download XNA studio and install that… more whirring, banging from my machine ensues.  Then, just in case things won’t recover gently, I decide to create the solution from scratch again.  After all, I hadn’t done anything yet.

Woohoo! all 4 projects successfully created!


Sweetness, right!?  So, I hit Ctrl-Shift-B (build command for you mouse-using pansies out there) and voila, everything builds!  Just kidding!  Now, I get this obvious and very helpful error:

Compile error -2147024770

(0, 0): error : Unknown compile error (check flags against DX version) D:\Dev\Book…Silverlight3dExample\Silverlight3dApp\CustomEffect.slfx

Umm.. OK.. Googling… googling… uh… yeah… Apparently, there’s another prerequisite missing that the installer also doesn’t check for: DirectX 9.  So, I download that and install (cringing at every single “installing XX update from 2006” message – how can that really not break my machine?).

Finally, it actually builds!  No thanks to the Silverlight Toolkit guys (well, some thanks, since they wrote it in the first place!), I can now continue to review this chapter of what really is a pretty killer book, you should buy it. Now.

Tuesday, January 10, 2012

Yes, I'm 12...

So, I moused over my explorer windows on my taskbar and this popped up:

Yep.. giggled like a 12 year old and told my friends about it :)