« Home | C# command line parser? » | Firefox extension: CookiePie » | Hand-held browser » | Silverlight » | Google Finance » | Link drop V » | ShowMeDo: WASTE tutorial » | Flash video » | TWOCrowds.com flickr CAPTCHA test » | SSL + Man-in-the-Middle » 

Monday, July 30, 2007 

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: