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,251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 63

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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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 63

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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

630 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