Bypassing Custom Content Build

Feb 23, 2012 at 4:56 PM

While porting my XNA Windows game to use Silverlight5Toolkit/SilverSprite, I'm running into several problems porting my game's relatively complicated custom content builders.  I was wondering whether it would be possible to use my windows built .xnb files directly, instead of porting the entire build process to work within my silverlight solution(?).

Feb 23, 2012 at 5:25 PM

I was thinking about this the other day, you should be able to add the XNB files to a Content folder in the root of your Silverlight application. all XNB files will need to be set to a build action of Content. Under this Content folder, use the same folder structure that your content project has. Please let me know if this works for you, otherwise I'll try it out myself.

Feb 23, 2012 at 6:16 PM
Edited Feb 24, 2012 at 2:24 PM

This does seem to work for images,  thanks!  Unfortunately, it's having trouble finding a ContentTypeReader for some of my custom data...

update: I'm slowly getting this working.  I needed to change some of my ported library's assembly names to match their windows counterparts, which seems reasonable.  However it seems that I also need to change the default constructors and other serialized members to public.  This seems odd and annoying, since it wasn't required in my windows app.  But it is resolving the access errors that I get otherwise.

update2: It looks like Silverlight locks down reflecting into private and protected members for security reasons (  So the default custom content readers and writers will only work on public members.

Apr 2, 2012 at 2:09 PM

As a follow up to this thread.  I've run into some trouble loading XNA Song content.  Whenever I try Content.Load<Song> from Silverlight3D, it throws an exception stating: "Cannot find ContentTypeReader Microsoft.Xna.Framework.Content.SongReader."  I have tried replacing this Song with a SoundEffect (since those are supported under Silverlight5), and this really bloats the size of the final XAP:

13.5MB XAP including sound effect based background music

1.5MB XAP without background music

2.9MB MP3 source background music

1.7MB XNB source music compiled into song (XNB+WMA)

12.8MB XNB source music compiled into sound effect (XNB)

Anyone suggestions about how I might load this music with a smaller memory footprint?  I'm thinking that my best option will be to look into Silverlight-specific music loading and playing methods, and to then create separate XNA and Silverlight implementations of my music class/interface.