Thursday, 25 June 2009

How do you solve a AG_E_PARSER_ BAD_TYPE error in Silverlight

For those developing Silverlight applications, you might be familiar with the error 'AG_E_PARSER_ BAD_TYPE'. This can occur both at design time or run time. It is one of those error messages that covers a multitude of sins and therefore proves hard to track down.

I recently got this error whilst developing a demo application to show off data binding in Silverlight 2. As is often the case, I had no idea why I was getting the error. In fact, I spent several hours on the net looking for the answer.

Many developers will identify with the '5 hours spent on a single error' experience.

Every post that I found described a different scenario and not one of them related to my situation. It was getting late and the Heineken family and I were getting pretty fed up with the whole thing.

In the end, I did what I always do when I hit a brick wall; I did something else to calm down. As this was to be a demo application and therefore viewed by many critical developers I set about tidying up the code.

Half an hour later I was ready to shut down and have a night cap when I hit F5 by reflex and "Crikey !" it worked.

So now I had the task of figuring out what I had done to make the error go away. I could have just left it alone but I was likely to see the error again one day and wanted to be prepared.

Luckily, the Heinekens were still around to keep me company and 10 minutes later I had the answer. Any longer and I would have had to call room service!

Now, I knew that the error was data related. This was a data binding demo application after all.

My error turned out to be related to my namespaces.

I had a namespace called SilverlightData and another nested within it called SilverlightData.DataClasses.

At different stages, I was using a class from one of these namepaces. And in the same way that I would happily leave multiple usings or imports at the top of a code file, I didn't see a problem with my namespace declarations in the xaml file.


During my tidy up, I removed the namespace declaration for SilverlightData as I was no longer using a class from there.

Hey presto ! Problem solved.

Now I am not sure if that was because there were no classes in SilverlightData in use in the current xaml file or that I was simply allowed one clr namespace. Neither sounds convincing. Perhaps you cannot declare nested namespaces ?

Either way, it was late by this point and dawn was close at hand.

I went to bed.

So if you encounter a AG_E_PARSER_ BAD_TYPE error in your Silverlight application and trawl the net in search of a solution, perhaps you will hit this page. Who knows, maybe this will help you solve the problem.

Then again it could be something else entirely.

Happy coding.


Should you require any training in Silverlight, QA offer the following courses:

Developing Rich Internet Applications Using Microsoft Silverlight 4

Developing Silverlight Applications with Visual Studio 2010 and Expression Blend 4

See you soon

Phil Stirpé
"I don't do average!"

No comments:

Post a Comment