Wednesday, August 25, 2004

Namespace "inheritance" and XmlSerializer

I've taken to writing much of my XML like this:


<foo:bar xmlns:foo="uri">
    <blah ... />
    <blah ... />
</foo:bar>


Which is to say, with an outermost element that's namespace qualified, but with all other elements belonging to no namespace. This is primarily laziness - I type a lot of XML by hand, and write a lot of XPath, and both are slightly easier with this sort of XML.


Where I got burned today was in trying to write a set of types that deserialize this XML. I started with this:


[XmlRoot("foo", Namespace="uri")]
public class Foo {
  private BlahCollection blahs = new BlahCollection(); 
 
  [XmlElement("blah")]
  public BlahCollection Blahs {
    get { return blahs; }
  }
}


And I expected it would work just fine. But I was surprised to find that when I did the deserialization, I got zero blahs in the resulting collection, even though there were two in the file. After banging my head against this problem for quite some time, I finally realized I needed to do something like this:


[XmlRoot("foo", Namespace="uri")]
public class Foo {
  private BlahCollection blahs = new BlahCollection(); 
 
  [XmlElement("blah", Namespace="")]
  public BlahCollection Blahs {
    get { return blahs; }
  }
}


Note that I'm explicitly setting the namespace to the empty string. Apparently, what was happening was that without this explicit command, the [XmlElement("blah")] attribute was assuming the Namespace value of the [XmlRoot] attribute above it. So at deserialization time, it was looking for an element called "blah" from the "uri" namespace, but finding one called "blah" that was from no namespace.


Although I know I'm nothing like the first person to come across this, it isn't called out in the docs in a way that was obvious to me, so I thought I'd mention it here.

Sunday, August 22, 2004

FlexWikiPad 0.93.1 Released - EnableVisualStyles Suspect

Ah, I have so much sympathy for Microsoft right now. I had just released version 0.93 of FlexWikiPad when I got email from several users complaining of some rather serious problems. Sure enough, I was able to verify them. D'oh!


Well, like any responsible software vendor, I committed to getting a patch out ASAP. And I did, just today: FlexWikiPad version 0.93.1 is available here. I think I got all the bad bugs that I know about. I certainly did a better job of testing this time.


There were about three different bugs that I had to address, but the worst one by far was a bit subtle. You see, users were experiencing actual crashes of the application when creating a new namespace. This was surprising to me because I had used this technique to catch unhandled exceptions. In my handler, I display a dialog box giving the user a chance to email me an exception report, and once they have, I let them go back to the application. In all the months I've been developing FlexWikiPad, this has always worked well enough to let me save my work whenever I hit some sort of unexpected problem. In other words, this was the first real “Oh *&%$ I lost work“ crash I'd seen.


The symptoms looked something like this: an unhandled exception would be thrown, after which the dialog would be displayed. The dialog would work fine (i.e. I could email myself an exception report), and then boom! The application would go down hard, with Application.Run() throwing an SEHException. This happens when someone in unmanaged code receives the dreaded COM HRESULT 0x80004005 (E_FAIL). This is a number I know well, but had hoped never to see again in my life.


I took a look at the code I've added to the application recently. On a whim, I tried removing from my Main the innocuous-looking line:


Application.EnableVisualStyles();


And sure enough, the problems went away. Which is to say, exceptions caused by bugs would still be thrown, but now they could be handled by my handler without an SEHException ensuing.


Needless to say, that line now looks like this:


// Application.EnableVisualStyles();


I can't say I understand why this change would fix the problem. EnableVisualStyles is the call you issue to ensure that you get support for Windows XP-style visual styles. Personally, I think they should have called it EnableUselessVisualFluff, but that's just me. A user requested it, so I wanted to try to support it. Of course, choosing between this and application stability was a pretty easy call.


What's really weird is that I just now compiled the source for version 0.93 to try to play around with this a bit, to see if I could maybe move the call around in Main to see what it would do. And now I can't get it to fail again. Sigh. Don't you just love software?


Either way, FlexWikiPad appears to be stable again. Download and enjoy.

Thursday, August 19, 2004

FlexWikiPad 0.93 Released

I've just released a new version of my major free-time black hole, FlexWikiPad. You can download version 0.93 here. New features in this, the latest version include:



So it's really coming along! My plans for the future look like this:


 Version 0.94 will probably be oriented toward a complete rewrite of the rendering engine, to make it totally customizable. That is, you'll be able to change a config file to add or alter: fonts, colors, and the regular expressions used to parse the document. I'll probably also take a look at performance, as I'm noticing some lag when typing in longer documents.


Version 0.95 will probably be about adding rudimentary online support, so separate usage of FwSync is not necessary. I'd also like to add a "Preview" function so you can see what your page will look like on the wiki to which you plan to post it.


Version 0.96 will probably be focused on adding hierarchical and historical navigation and fixing the tree view so it actually works.


And then if that's all the major features I can think of, I'll focus on fixing bugs, cleaning up the code, performance, and stability en route to a 1.0 release. If I can get all this done before the baby is born, so much the better.


Of course, for all I know, I'm the only one actually using the thing. But regardless, it's been an interesting experience writing a GUI app, which is not something I usually do. It's been particularly interesting developing it with a TDD approach, as GUIs present some unique challenges.

SHA-1 On the Ropes?

I'm not sure if you've seen this by now or not, but it's potentially devastating news for security pretty much everywhere if it turns out that SHA-1 has serious vulnerabilities.

Tuesday, August 17, 2004

I Need to Learn to RelaxNG

When Tim Ewald says XSD is too complicated, you know that at best the technology might be...a tad overengineered. So perhaps it's time to look into RelaxNG, an alternate schema language that lacks a lot of the weird complexities of XSD.

In truth, I've looked briefly at RelaxNG in the past. I found the basics to be very easy to understand...unlike XSD. But I haven't tried to use it in earnest yet, so my opinion is necessarily unformed. I think I'll make it a goal to use RelaxNG in some real context at the next opportunity where it's practical to do so.

Sunday, August 15, 2004

CruiseControl.NET Configuration

If you haven't checked out CruiseControl.NET yet, you really ought to. Continuous Integration (CI) is, in my opinion, only slightly behind Test Driven Development on the list of “most important software development techniques I've ever encountered,” and that puts it very high indeed. I've found CruiseControl.NET to be far more flexible and reliable than Draco.NET, the other major .NET CI tool.


Recently, I took on the role of buildmaster for FlexWiki. As we make the move to SourceForge, I thought it would be an opportune moment to get a CI system set up, primarily because it would help us avoid the “source code, source code, who's got the source code” hell that we've been in for months now. So as I sat down and set up a CruiseControl instance, I had a chance to think about our needs, and about how we should configure things to allow us to grow the project.


Well, after thinking about it for a while, I came up with something I rather like. Since it differs somewhat from the out-of-the-box CruiseControl experience, I've gone ahead and written up what I did here. Hopefully someone else will find it helpful.

Saturday, August 14, 2004

Conference Envy

There are two conferences I'd really like to go to this year: WinDev and the Applied XML Developer’s Conference 5. The confernces are both in late October, and both look to be awesome...just check the spearker list. I was invited to submit a talk to both of them, but had to refuse in both cases: my wife is pregnant, and her due date is right around then. Technically, she did say I could go, but she told me to buy a one-way ticket if I did. :)