RonenNess / GeonBit.UI

UI system for MonoGame projects.
MIT License
477 stars 64 forks source link

Getting InvalidCastException when trying to run basic empty project #101

Closed torial closed 5 years ago

torial commented 5 years ago

Trying to run basic demo (just the cursor, nothing else) and getting an invalid cast exception in the UserInterface.Initialize method:

System.InvalidCastException
  HResult=0x80004002
  Message=Unable to cast object of type 'Microsoft.Xna.Framework.Graphics.Texture2D' to type 'GeonBit.UI.DataTypes.CursorTextureData'.
  Source=MonoGame.Framework
  StackTrace:
   at Microsoft.Xna.Framework.Content.ContentReader.InnerReadObject[T](T existingInstance)
   at Microsoft.Xna.Framework.Content.ContentReader.ReadObject[T]()
   at Microsoft.Xna.Framework.Content.ContentReader.ReadAsset[T]()
   at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action`1 recordDisposableObject)
   at Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName)
   at GeonBit.UI.Resources.LoadContent(ContentManager content, String theme)
   at GeonBit.UI.UserInterface.Initialize(ContentManager contentManager, String theme)
   at GeonBit.UI.UserInterface.Initialize(ContentManager contentManager, BuiltinThemes theme)
   at Project1.Project1.Initialize() in C:\Users\User1\source\repos\Project1\Project1\Game1.cs:line 30
   at Microsoft.Xna.Framework.Game.DoInitialize()
   at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
   at Project1.Program.Main() in C:\Users\User1\source\repos\Project1\Project1\Program.cs:line 17

--- I'm not sure if this is related, but before I got to this point, I had a runtime exception of not finding \bin\DesktopGL\AnyCPU\Debug\Content\GeonBit.UI\themes\hd\textures\cursor_default_md.xnb so I renamed the cursor_default.xnb to the missing name to get past that error.

RonenNess commented 5 years ago

Hi @Torial, In the textures folder for every texture there's the texture file itself, + texture metadata (ending with _md) which is actually xml. So the error you're getting is due to the file you renamed :)

Now the question is why you were missing the original file - did you download repo as zip or nuget? Is it possible you somehow didn't copy or included all files?

To solve it please make sure the file exists, if it's missing you can get it from the repo. Maybe easiest way would be to remove the entire geonbit.ui content folder and download / add it again, this way we'll know you have everything right.

Let me know if it's working so I can close this issue :)

torial commented 5 years ago

I downloaded it via Nuget [in addition to the steps on the Readme] had to do the following to get it to compile: All the XMLs were causing the Content manager to give XML Importer errors, so I made them all "Copy" instead of "Build".

I renamed the cursor_default_md.xnb back -- and still get the I had a runtime exception of not finding \bin\DesktopGL\AnyCPU\Debug\Content\GeonBit.UI\themes\hd\textures\cursor_default_md.xnb.

If I remove the content again and re-add it, I get back to the XML files failing to Build (313 files failed). Was my choice of changing them over to Copy the wrong choice?

RonenNess commented 5 years ago

Looks like you forgot this step:

Add a Reference to the DataTypes.dll lib, located in packages\GeonBit.UI.<version>\lib\geonbitui\ https://github.com/RonenNess/GeonBit.UI#via-nuget

(note that its a reference in the Content Manager, not in the project) You don't need to rename any files, they are working for everyone else :) Try the step I added above and let me know if it worked.

Thanks!

torial commented 5 years ago

Hi, I had already done that step as it was one of the 2 steps listed in the Readme for getting Content setup. Here's the entry in the mgcb for the DataTypes Library:

#---------------------------------- Content ---------------------------------#

#begin ../../packages/GeonBit.UI.3.4.0/lib/geonbitui/DataTypes.dll
/importer:
/processor:
/build:../../packages/GeonBit.UI.3.4.0/lib/geonbitui/DataTypes.dll;DataTypes.dll

For the XML files, unless I put them in Copy mode, I get for each XML file Importer 'XmlImporter' has unexpected failure! System.Reflection.ReflectionTypeLoadException: Unable to load one or more requested types . Is Copy the right way to solve this? Does this work for you without changing the Build Action from Build to Copy for _md.xml files?

RonenNess commented 5 years ago

Yes you don't need to rename or change any of the files copy mode, they are supposed to compile. Do you want to upload the project somewhere as zip so I will take a look?

DavidFidge commented 5 years ago

One thing the Install instructions don't mention is that you need to have DirectX 9c installed. There's several effects files that have a dependency on it. Without it installed you'll get the unexpected failure messages.

torial commented 5 years ago

Thank you DireAussie, Unfortunately while I had set up the game using the open GL based MonoGame Cross Platform Desktop Project (as I was hoping to test it on Mac), so when I try this with the MonoGame Windows Project (that explicitly references DirectX) (and after explicitly install DirectX 9c), I have the same issues.

RonenNess - I have put the 7z compressed files here: https://transfernow.net/ddl/torial

Thank you for looking!

RonenNess commented 5 years ago

@torial ah I see what's the problem, you didn't add reference properly. When adding a reference to the content manager you're not suppose to add the dll like an asset, you're supposed to select root directory (the node that has MG icon and called "Content") and click on 'References' in its properties menu. Please see following screenshot:

image

In addition you need to exclude the dll you added as an asset, its not supposed to be there. This should fix your problem :)

torial commented 5 years ago

Thanks for looking. When I’m a little more solid on this I will help with documenting the setup process.