Solved

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll  There was an error reflecting type 'XNA RPG Library.Entity Class'.

Posted on 2010-09-02
17
1,122 Views
Last Modified: 2012-05-10
I am trying to get some code that comes with a book "RPG Programming using XNA Game Studio 3.0" to run.  The code complies and runs, but I get the following error:

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll  There was an error reflecting type 'XNA RPG Library.Entity Class'.

when the program tries to load "cleric.xml".

I was hoping someone could tell me the most likely causes of this and suggestions on how to correct it.  I will be glad to upload any code that you might need to look at.
0
Comment
Question by:doug5516
  • 9
  • 6
  • 2
17 Comments
 
LVL 9

Expert Comment

by:richard_hughes
ID: 33587924
Hello doug5516

If you could post the call stack of the error, that would be very helpful.

My guess without that would be something wrong with the XML document, perhaps it is missing, read only, incorrect syntax maybe. Or it could be that Library.Entity is throwing the error because it cannot load a resource.

Thanks,

Richard Hughes
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 33587964
Can you upload the "cleric.xml" file here.
0
 

Author Comment

by:doug5516
ID: 33588030
Okay, here is the call stack

       System.Xml.dll!System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(System.Xml.Serialization.TypeModel model = {System.Xml.Serialization.StructModel}, string ns, System.Xml.Serialization.XmlReflectionImporter.ImportContext context, string dataType, System.Xml.Serialization.XmlAttributes a, bool repeats, bool openModel, System.Xml.Serialization.RecursionLimiter limiter) + 0x656 bytes      
       System.Xml.dll!System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(System.Xml.Serialization.TypeModel model, string ns, System.Xml.Serialization.XmlReflectionImporter.ImportContext context, string dataType, System.Xml.Serialization.XmlAttributes a, System.Xml.Serialization.RecursionLimiter limiter) + 0x1d bytes      
       System.Xml.dll!System.Xml.Serialization.XmlReflectionImporter.ImportElement(System.Xml.Serialization.TypeModel model = {System.Xml.Serialization.StructModel}, System.Xml.Serialization.XmlRootAttribute root = null, string defaultNamespace, System.Xml.Serialization.RecursionLimiter limiter) + 0x7e bytes      
       System.Xml.dll!System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(System.Type type = {Name = "EntityClass" FullName = "XNA_RPG_Library.EntityClass"}, System.Xml.Serialization.XmlRootAttribute root = null, string defaultNamespace = null) + 0x62 bytes      
       System.Xml.dll!System.Xml.Serialization.XmlSerializer.XmlSerializer(System.Type type = {Name = "EntityClass" FullName = "XNA_RPG_Library.EntityClass"}, string defaultNamespace = null) + 0x1ce bytes      
       System.Xml.dll!System.Xml.Serialization.XmlSerializer.XmlSerializer(System.Type type) + 0x7 bytes      
>      XNA RPG Toolset.exe!XNA_RPG_Toolset.ClassesForm.LoadClass(string filename = "L:\\Gaming\\XNARPG\\XNARPGBookCode\\Chapter 6\\XNA RPG Toolset\\bin\\x86\\Debug\\Games\\Test\\classes\\Cleric.xml") Line 292 + 0x25 bytes      C#
       XNA RPG Toolset.exe!XNA_RPG_Toolset.ClassesForm.ClassesForm(string gameName = "Test") Line 45 + 0xb bytes      C#
       XNA RPG Toolset.exe!XNA_RPG_Toolset.MainForm.ShowClassesForm(object sender = {&Classes}, System.EventArgs e = {System.EventArgs}) Line 94 + 0x2b bytes      C#
       System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.RaiseEvent(object key, System.EventArgs e) + 0x58 bytes      
       System.Windows.Forms.dll!System.Windows.Forms.ToolStripMenuItem.OnClick(System.EventArgs e) + 0x46 bytes      
       System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.HandleClick(System.EventArgs e) + 0x6e bytes      
       System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.HandleMouseUp(System.Windows.Forms.MouseEventArgs e = {X = 18 Y = 10 Button = Left}) + 0x1d8 bytes      
       System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.FireEventInteractive(System.EventArgs e, System.Windows.Forms.ToolStripItemEventType met) + 0x61 bytes      
       System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.FireEvent(System.EventArgs e, System.Windows.Forms.ToolStripItemEventType met) + 0x118 bytes      
       System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.OnMouseUp(System.Windows.Forms.MouseEventArgs mea) + 0xb2 bytes      
       System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons button, int clicks) + 0x28f bytes      
       System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x885 bytes      
       System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) + 0x2a bytes      
       System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.WndProc(ref System.Windows.Forms.Message m = {msg=0x202 (WM_LBUTTONUP) hwnd=0xd210ce wparam=0x0 lparam=0xc00a7 result=0x0}) + 0x71 bytes      
       System.Windows.Forms.dll!System.Windows.Forms.MenuStrip.WndProc(ref System.Windows.Forms.Message m) + 0x27 bytes      
       System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x10 bytes      
       System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x31 bytes      
       System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 514, System.IntPtr wparam, System.IntPtr lparam) + 0x57 bytes      
       [Native to Managed Transition]      
       [Managed to Native Transition]      
       System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = -1, int pvLoopData = 0) + 0x24e bytes      
       System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x177 bytes      
       System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x61 bytes      
       System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) + 0x31 bytes      
       XNA RPG Toolset.exe!XNA_RPG_Toolset.Program.Main() Line 17 + 0x1d bytes      C#
       [Native to Managed Transition]      
       [Managed to Native Transition]      
       mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x3a bytes      
       Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x2b bytes      
       mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x66 bytes      
       mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x6f bytes      
       mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 bytes      

And I have included the "cleric.xml" file
System.Xml.dll!System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(System.Xml.Serialization.TypeModel model = {System.Xml.Serialization.StructModel}, string ns, System.Xml.Serialization.XmlReflectionImporter.ImportContext context, string dataType, System.Xml.Serialization.XmlAttributes a, bool repeats, bool openModel, System.Xml.Serialization.RecursionLimiter limiter) + 0x656 bytes	
 	System.Xml.dll!System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(System.Xml.Serialization.TypeModel model, string ns, System.Xml.Serialization.XmlReflectionImporter.ImportContext context, string dataType, System.Xml.Serialization.XmlAttributes a, System.Xml.Serialization.RecursionLimiter limiter) + 0x1d bytes	
 	System.Xml.dll!System.Xml.Serialization.XmlReflectionImporter.ImportElement(System.Xml.Serialization.TypeModel model = {System.Xml.Serialization.StructModel}, System.Xml.Serialization.XmlRootAttribute root = null, string defaultNamespace, System.Xml.Serialization.RecursionLimiter limiter) + 0x7e bytes	
 	System.Xml.dll!System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(System.Type type = {Name = "EntityClass" FullName = "XNA_RPG_Library.EntityClass"}, System.Xml.Serialization.XmlRootAttribute root = null, string defaultNamespace = null) + 0x62 bytes	
 	System.Xml.dll!System.Xml.Serialization.XmlSerializer.XmlSerializer(System.Type type = {Name = "EntityClass" FullName = "XNA_RPG_Library.EntityClass"}, string defaultNamespace = null) + 0x1ce bytes	
 	System.Xml.dll!System.Xml.Serialization.XmlSerializer.XmlSerializer(System.Type type) + 0x7 bytes	
>	XNA RPG Toolset.exe!XNA_RPG_Toolset.ClassesForm.LoadClass(string filename = "L:\\Gaming\\XNARPG\\XNARPGBookCode\\Chapter 6\\XNA RPG Toolset\\bin\\x86\\Debug\\Games\\Test\\classes\\Cleric.xml") Line 292 + 0x25 bytes	C#
 	XNA RPG Toolset.exe!XNA_RPG_Toolset.ClassesForm.ClassesForm(string gameName = "Test") Line 45 + 0xb bytes	C#
 	XNA RPG Toolset.exe!XNA_RPG_Toolset.MainForm.ShowClassesForm(object sender = {&Classes}, System.EventArgs e = {System.EventArgs}) Line 94 + 0x2b bytes	C#
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.RaiseEvent(object key, System.EventArgs e) + 0x58 bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStripMenuItem.OnClick(System.EventArgs e) + 0x46 bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.HandleClick(System.EventArgs e) + 0x6e bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.HandleMouseUp(System.Windows.Forms.MouseEventArgs e = {X = 18 Y = 10 Button = Left}) + 0x1d8 bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.FireEventInteractive(System.EventArgs e, System.Windows.Forms.ToolStripItemEventType met) + 0x61 bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.FireEvent(System.EventArgs e, System.Windows.Forms.ToolStripItemEventType met) + 0x118 bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.OnMouseUp(System.Windows.Forms.MouseEventArgs mea) + 0xb2 bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons button, int clicks) + 0x28f bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x885 bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) + 0x2a bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.WndProc(ref System.Windows.Forms.Message m = {msg=0x202 (WM_LBUTTONUP) hwnd=0xd210ce wparam=0x0 lparam=0xc00a7 result=0x0}) + 0x71 bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.MenuStrip.WndProc(ref System.Windows.Forms.Message m) + 0x27 bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x10 bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x31 bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 514, System.IntPtr wparam, System.IntPtr lparam) + 0x57 bytes	
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = -1, int pvLoopData = 0) + 0x24e bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x177 bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x61 bytes	
 	System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) + 0x31 bytes	
 	XNA RPG Toolset.exe!XNA_RPG_Toolset.Program.Main() Line 17 + 0x1d bytes	C#
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x3a bytes	
 	Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x2b bytes	
 	mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x66 bytes	
 	mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x6f bytes	
 	mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 bytes

Open in new window

Cleric.xml
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 9

Expert Comment

by:richard_hughes
ID: 33588073
Hello

It could be that the system cannot find the class XNA_RPG_Library.EntityClass

Have you ensured that the project has compiled properly and all references are avaliable?

Thanks,

Richard Hughes
0
 

Author Comment

by:doug5516
ID: 33588240
I am assuming that it compiles properly as I do not get any errors during compilation.  The program will start and run.  It only crashes when the program attempts to load the "cleric.xml" file.
0
 
LVL 9

Expert Comment

by:richard_hughes
ID: 33588256
Does it crash with any other XML file being used?
0
 
LVL 9

Expert Comment

by:richard_hughes
ID: 33588263
And by XML file, I mean any other of that type.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 33588267
The file "cleric.xml" looks to be well formed so should not be the issue.
0
 

Author Comment

by:doug5516
ID: 33588327
I agree with Fernando, I don't think it is the XML file itself.  But to be more certain I removed the "cleric.xml" file so that the program would start with a different file "fighter.xml" and I get the same result

There was an error reflecting type 'XNA_RPG_Library.EntityClass'.

So I think it must be something within the class, EntityClass, itself that is causing the reflection error.  I just don't know how to figure out what would cause it.
0
 
LVL 9

Assisted Solution

by:richard_hughes
richard_hughes earned 500 total points
ID: 33588378
That makes sense. There are two options,

1) Debug the code and step through to see exactly what the error is

2) Post the code and we will have a look to see if we can see it

Thanks
0
 
LVL 9

Expert Comment

by:richard_hughes
ID: 33588387
Is that class stored in a seperate DLL? If so, maybe that DLL cannot be found.
0
 

Author Comment

by:doug5516
ID: 33588415
1) Debug the code and step through to see exactly what the error is

I have found the line of code that throws the error:

XmlSerializer serializer = new XmlSerializer(typeof(EntityClass));

And the error I get is

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll

Additional information: There was an error reflecting type 'XNA_RPG_Library.EntityClass'.

Should I do something to get more specific error information.  I do not mind at all posting the code, but there is a lot of code with a lot of dependencies.
0
 
LVL 9

Accepted Solution

by:
richard_hughes earned 500 total points
ID: 33588495
It seems there is an error with how XmlSerializer is managing EntityClass

Try having a look here to see if you can narrow down the issue:

http://msdn.microsoft.com/en-us/library/71s92ee1.aspx
http://www.eggheadcafe.com/articles/system.xml.xmlserialization.asp

Thanks
0
 

Author Comment

by:doug5516
ID: 33588573
Is that class stored in a seperate DLL? If so, maybe that DLL cannot be found.

The file is in a separate DLL, but the program is finding other classes that are also in the DLL, so I do not think the the program can not find the DLL.  I will take a look at the two links that richard hughes posted but it will be tomorrow before I can as I now have to go to the dreaded job
0
 
LVL 9

Expert Comment

by:richard_hughes
ID: 33588585
OK

Also make sure that the class is marked as 'public' - as that could have an impact in reflection being able to see it.
0
 

Author Comment

by:doug5516
ID: 33696761
Did not mean to close it.
0
 
LVL 9

Expert Comment

by:richard_hughes
ID: 33708342
How is the status of this error?
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question