This project is read-only.

[SOLVED] Problem loading .skin.xml from Resource or XNA Content

Sep 6, 2012 at 12:28 PM
Edited Sep 6, 2012 at 2:26 PM


I'm having some trouble loading a a skin definition file from a resource.

I have UserInterfaceBeeb.resx containing BeebSkin which points to Resources\UserInterface\

The contents of that file are taken from the nuclex source package and modified to point to BeebSheet.png instead of SuaveSheet.png

I've added skin.xsd to the solution.

I've added an XNA Content Project called NuclexContent and to that I've added BeebSheet.png, DefaultFont.spritefont, TitleFont.spritefont

I have not yet added BeebSheet.xnb, DefaultFont.xnb, TitleFont.xnb to UserInterfaceBeeb.resx yet, mainly because I haven't figured out the paths yet.

In my game  constructor I have: 


Nuclex.UserInterface.Visuals.Flat.FlatGuiVisualizer Viz;
Viz = Nuclex.UserInterface.Visuals.Flat.FlatGuiVisualizer.FromResource(Services, Resources.UserInterfaceBeeb.ResourceManager, "BeebSkin");

When I run it, FromResource throws the error:


Unable to cast object of type 'System.String' to type 'System.Byte[]'.


I've never worked with resources or xna content so I'm at a loss about what to do.

Is this just because I haven't got around to adding the .xnb files to the xna content project? Or something else?

I'd appreciate any help anyone can give. Thanks.



I tried this line:  Viz = Nuclex.UserInterface.Visuals.Flat.FlatGuiVisualizer.FromFile(Services, "Resources\\UserInterface\\Beeb\\");

and specified that be copied to the output directory. It finds the file ok but throws the exception:
The GraphicsDevice must not be null when creating new resources.
Parameter name: graphicsDevice

---Edit again---
I see now I was calling the FromFile too early. I called it in Initialize and it no longer throws the ArgumentNullException and just throws an exception about missing fonts (which I expected).

I'm still curious to know what I'm doing wrong with the resources method, but I can proceed using FromFile now.

---Edit again---

I got the spritefont files to compile to Nuclex Framework sprite fonts through the nuclex font importer but now when debugging I get the following exception:

Error loading "TitleFont". File not found.

The InnerException to that is:
Error loading "Resources\UserInterface\Beeb\TitleFont.xnb". File not found.

I verified that the xnb files were built and exist in:


What am I doing wrong?

Sep 6, 2012 at 2:36 PM

It's been some time since I did that, but I think if you select a resource and open the properties window, you can select whether it will be stored as a System.String or as an array of bytes.

Regarding your file not found issue, maybe you didn't assign the base directory to the content manager? For some absurd reason, Visual Studio by default launches projects with the directory that contains the .csproj file as the current working directory instead of bin\x86\${Configuration}, so your path could very well be interpreted as GameSolution\Resources\UserInterface\Beeb\TitleFont.xnb if the content manager has no base directory assigned.

Sep 6, 2012 at 2:58 PM
Edited Sep 6, 2012 at 4:25 PM

I have the line:

  Content.RootDirectory = "Content";

Is this base directory you are talking about? Or do you mean the working directory in the solution properties Debug tab?

This works to load a vanilla xna spritefont using the following code:


this._Font = Content.Load<SpriteFont>("Fonts\\OldFont");


The Resources folder containing the new Nuclex xnb files is sitting parallel to this old Fonts folder.

(Thanks for the quick reply BTW)


Just to be clear, after building my directory structure looks like:



FromFile seems to be looking for the fonts in the same dir as the skin.xml exactly as the path is specified in the path parameter. I don't see how they can ever match up seeing as the TitleFont is part of the the Content Project and the skin.xml is just added to the main game project and copied to the output directory at build time. I'm definitely misunderstanding how this is supposed to work.

Sep 6, 2012 at 5:19 PM
Edited Sep 6, 2012 at 5:50 PM

After I do Content.RootDirectory = "Content"
Do I need to do anything with that to let the Nuclex know about it?

Sep 6, 2012 at 5:49 PM
Edited Sep 6, 2012 at 6:31 PM

I got it!

I added a new folder to the main solution which I name "Content" to match the Content Project output folder name and then moved the Resources folder containing into that. The output folder structures then matched and it all worked.


Thanks for the help!    :-)


Except that it's drawing all text on controls a few pixels too low vertically.
I tried it again with clean copies of the nuclex source spritefonts and SuaveSheet.png and it also draws that text too low (or the sheet graphics too high, I can't tell).
If I comment out:

 Viz = Nuclex.UserInterface.Visuals.Flat.FlatGuiVisualizer.FromFile(Services,  "Content\\Resources\\UserInterface\\Beeb\\");
gui.Visualizer = Viz;


then the default skin displays properly.

If I edit the and modify all the <text yoffset="15"> attributes to <text yoffset="0"> It looks correct. But I'm using the default files apart from changing to read:   <bitmap name="controls" contentPath="BeebSheet" />
There are no other changes, so I don't understand why it's occuring.

Any ideas?



I see my new problem is a duplicate of this one:
I've used the supplied source spritefonts and built them with the Nuclex SpriteFont processor though. I'm just going to modify the yoffset attributes for now.