Silverlight createFromXaml Bug
|
The article you are reading has moved! It is now available at: http://blog.tinisles.com/2007/07/silverlight-createfromxaml-bug/ |
Odd Silverlight bug when calling 'createFromXaml' - here's the error for the search engines:
Firefox:Error calling method on NPObject!
Internet Explorer: Error: AG_E_RUNTIME_METHOD : CreateFromXAML
The error occurred when I was trying pull apart the Video Library Sample for my own project.
The cause of the bug comes down to this:
- Using the replaceAll prototype to get a string which is passed to createFromXaml:
- works fine when it finds the placeholder and replaces it
- crashes when it doesn't find the placeholder in the string.
Have a look at an example: Silverlight createFromXaml bug. I'm writing out the string I'm using with createFromXaml in the textarea. The first button uses the untouched template, the second replaces the $2 placeholder, and the third attempts to replace a non-existent $3 placeholder.
Stripping all the functionality out of replaceAll causes the error to happen everytime - suggesting Silverlight has a problem dealing with an untouched 'this' coming from a prototype method on a string.
String.prototype.replaceAll = function(strTarget, strSubString) { var strText = this; return( strText ); }
I've created a post about it in the Silverlight forums: BUG: createFromXaml and prototypes.
Labels: silverlight