Avalon tip of the day

When an Avalon app starts up, it parses the XAML file, and as it parses the file, it creates the object tree.

Creating the object tree requires that the constructors for the objects be called. And if one of those constructors were to fail, you get a XamlParseException. Something like:

Cannot create instance of ‘Window1’ defined in assembly ‘WindowsApplication4, Version=1.0.2480.23268, Culture=neutral, PublicKeyToken=null’. Exception has been thrown by the target of an invocation.  Error in markup file ‘Window1.xaml’ Line 1 Position 9.

And then you spend a few minutes trying to figure out what is wrong with your XAML file that’s making the parse fail. What’s wrong with Line 1 Position 9…

If you see a XAML parse error, you might want to check that out. Or you could do things the right way and hook up to the Initialized or Loaded events instead of putting your code in the constructor.

Comments (6)

  1. RichB says:

    I thought. Yea. D’uh. So what?

    But then I realized that having done tons of ASP.Net, it’s just natural not to use the constructor and instead define a void Page_Load() {} to do control initialization tasks.

  2. anony.muos says:

    Hey Eric,

    This is not regarding this post but rather about DVD Maker. In your FAQ, you had mentioned that an XML file can be passed to DVD Maker and then it’ll finish off….what I want to know is the XML file will be only for the burning part or the encoding of MPEG-2 (+Dolby) content too…meaning can we pass an XML file to DVD Maker so that it’ll encode the content in MPEG-2 (Dolby audio) and then burn it or that file is only for MPEG-2 complaint content only passed to DVD Maker for burning?

  3. someone,

    I added an entry to the FAQ for that.

    Using the project file support in DVD maker the same as adding files through the UI. If the content file works through the UI case, it will work through the passing the XML project file on the command line.

  4. Kris says:

    Makes sense, however; it does seem a little counter intuitive to how most people grok initialization and exception messages.  

  5. Tyler Jensen says:

    I’ve never caught the groove of XAML. Can anyone point me to a great starting place?



  6. Tyler,

    My advice is to go and write some avalon code and do as much as possible through code rather than through XAML. I found it made a lot more sense to me to approach things that way initially, and convert to the XAML-based approach when I wanted to.