After upgrading from SilverLight 2.0 Beta 1 to SilverLight 2.0 Beta 2 I started receiving the following strange behavior. The project would compile just fine (and execute with no issue), but he design view of my XAML page stopping showing the preview. Although the project compiled just fine, with zero failures, if you look in the error list, you would see an error.
AG_E_UNKNOWN_ERROR in file Page.xaml
Well it turns out the XAML parse error was not in the Page.xaml. It was related to a UserControl that I had built, that was included on the page. Oddly enough however, what looked like a parse exception was not related to the XAML in the user control either. The problem was in the code behind of the user control. Specifically, I had put code into the constructor of the user control.
My constructor was setting up two event handlers for the user control. In the first one, the user control was subscribing to an event in the parent page. In the second one, the user control was subscribing to a static class that raises an event when new data is received from the database. It was this second line that was causing the issue. After removing this one line, the error went away and the design view started working. Keep in mind this worked just fine in Beta 1.
So there are a few lessons learned here. First, if you are receiving an AG_E_UNKNOWN_ERROR referencing an XAML file don’t assume that the error has anything to with either XAML or that file. Start removing user controls to pinpoint where the error may be. Second, use the onLoad event in your user controls. This may be an obvious statement to well seasoned developers of user controls, but it appears the constructors execute when viewing a control in design time (but you can’t hit a breakpoint). This makes sense after the fact, but when it works just fine in Beta 1, you wouldn’t think to change it in Beta 2, especially when the error is far away from the cause.
One last little tidbit, the error did not occur after I had removed the control from the page. When the control is standalone, no issue. When included as part of the markup in the page.xaml file, the error was present and the design view stopped working for the page (design view worked just fine for the control). Needless to say this was a tough one to track down, as all symptoms seemed to point you away from an issue in the control, especially the real cause.