Target Invocation exception while dynamically loading XAP

Jul 25, 2010 at 6:08 PM


The problem occurs when dynamically loading the XAP when I have the following XAML tag:

<local:myGame x:Name="GameControl" Width="1366" Height="768"/>

This is the portion of code that throws the exception

UIElement page = asm.CreateInstance(filePage) as UIElement ;

In the Details of the exception a portion states:

InnerException: System.Windows.Markup.XamlParseException
Message=System.ArgumentNullException: Value cannot be null.

I'm guessing that this may be the same reason that Visual Studio says "Cannot create instance of "myGame" in the xaml editor.

I'm not that concerned about Visual Studio not displaying the control, but I really need to be able to dynamically load the XAP file. The game works fine if run on its own, it just doesn't like to be dynamically added to another page.

Is there anything I can do to get around this?


Jul 25, 2010 at 11:51 PM

The reason the designer is failing has to do with the Runtime not being properly initialized due to a tight coupling I had to do that I've been working on loosening up. In fact, in the next version, this coupling has been decoupled and one step closer to getting design-time support.

The problem you're seeing might be somewhat related. The coupling I'm talking about is a typediscover mechanism that discovers the platform its running on, and the Silverlight specific platform implementation relies in a separate DLL called Balder.Silverlight. It discovers this by getting AssemblyParts from the current Deployment. I was under the impression that the Current deployment would point to the XAP file it resided in, but I might be wrong here. I haven't really tested this scenario. 

It would be interesting to see if this problem goes away with the next drop of Balder. You could go get the current source code and compile it for yourself and give it a try - but beware, all namespaces has changed from Balder.Core to Balder and if you used the Animation extensions in Balder.Silverlight, they are now in the Balder.Animation namespace.


Jul 27, 2010 at 4:24 PM

With the new release (, the exception is gone as long as you set Width and Height. 

Also worth mentioning, the new screencast for getting started :

Jul 27, 2010 at 8:41 PM
Forgot to be specific here; the designer exception is the one that has been "fixed"
Jul 27, 2010 at 8:42 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.