This is the second post in a series about bugs you can’t avoid, can’t predict, and can’t even diagnose without significant time investment. Bugs that aren’t your fault, because they are in your tools. The bane of time estimates and deadlines, the unfathomable bug.

Today’s bug comes courtesy of Microsoft. Thank you, Microsoft, this series wouldn’t exist without the generous support of entities like you.

—

After diagnosing and avoiding the triply nested namespaces bug, I was feeling quite pleased with myself. The project built, started, ran … and promptly died after five seconds.

The problem appeared simple. The crash occurred during file IO, and I noticed the code was not using the WinRT API. Probably something one of my fellow programmers found on the web when trying to do synchronous IO. It worked fine before, but maybe Microsoft tightened the rules for Windows 8 RTM (the IO API in WinRT is entirely asynchronous). I rewrote the offending code to do things the “right” way (but cheated a little by blocking on the async results).

Naturally, being unfathomable, the crash didn’t go away. My next guess was that the file wasn’t present, due to a recent merge resolution error or other minor mistake. Indeed, some files being asked for were not present, but in each case it was clear that this was intentional (the caller explicitly checked if the load succeeded or not). More importantly, the crash still occurred even when the file did exist.

I tried more things. Suffice it to say that they became more and more absurd, because the real problem was so unbelievably stupid. I really feel that I can’t do it justice so… just… here’s the fix:

—

…

- var file = await root.GetFileAsync(path); + var file = await root.GetFileAsync(path.Replace("/", "\\"));

…

—

Some of the file IO methods don’t handle the alternate directory character (‘/’ instead of ‘\’) correctly. The file IO methods in WinRT. An API by Microsoft. For Windows. Where it is universally expected that both forward and backward slashes are directory separators.

What. The. F-

—

Don’t believe me? Try it for yourself. Create a new C# windows store project, and put the following code inside the OnNavigatedTo function in MainPage.xaml.cs (or anywhere else where it runs when you start the project):

var root = Windows.ApplicationModel.Package.Current.InstalledLocation; var t1 = root.GetFileAsync("Assets\\Logo.png").AsTask(); var t2 = root.GetFileAsync("Assets/Logo.png").AsTask(); t1.Wait(); // works fine, task succeeded t2.Wait(); // ERROR



Twisted Oak Studios offers consulting and development on high-tech interactive projects. Check out our portfolio, or Give us a shout if you have anything you think some really rad engineers should help you with.



Archive