No Free Time

Because my therapist says I need to let things out

Explanation for a weird Visual Studio 2008 Silverlight 2 issue

Posted by andrewmyhre on January 22, 2009

I ran into a weird and annoying Silverlight/Visual Studio quirk today which cost me a little bit of time to work out the cause of, so here’s my story in case it helps anyone else out.

If you’re building a Silverlight Page/UserControl and you run it and instead of seeing your lovely application appear you see something like this:

 

 

(line 1, col 26): Unknown attribute xmlns on element WallContentView”]weird error

Sys.InvalidOperationException: Invalid XAML for control 'Xaml1'. [

 

And you notice in the XAML where you have included your control some blue lines:

 

 

021

 

And when you place your mouse cursor over the lines you see something incomprehensible, like this:

 

 

“]031

AG_E_UNKNOWN_ERROR [Line: 49 Position: 51

 

I did today. After trying essentially random and arbitrary things to solve the issue (deleting and recreating the control, renaming the control, removing sections of XAML and code from the control) I finally narrowed it down to this:

 

 

041

 

In my constructor I was causing an null reference error, but it was being reported as a XAML error! How bloody confusing.  And the reason this didn’t twig immediately is that I didn’t realise the XAML editor actually creates instances of the control tree and invokes the constructors of the controls in the process. Never occurred to me before, but makes total sense.

Anyway, so I fixed my code:

051

 

Rebuilt the solution and checked the containing control’s XAML:

061

 

No more blue lines – nice. Finally I ran my test page and lo and behold it worked!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>