• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1410
  • Last Modified:

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

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
doug5516
Asked:
doug5516
  • 9
  • 6
  • 2
2 Solutions
 
richard_hughesCommented:
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
 
Fernando SotoCommented:
Can you upload the "cleric.xml" file here.
0
 
doug5516Author Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
richard_hughesCommented:
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
 
doug5516Author Commented:
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
 
richard_hughesCommented:
Does it crash with any other XML file being used?
0
 
richard_hughesCommented:
And by XML file, I mean any other of that type.
0
 
Fernando SotoCommented:
The file "cleric.xml" looks to be well formed so should not be the issue.
0
 
doug5516Author Commented:
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
 
richard_hughesCommented:
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
 
richard_hughesCommented:
Is that class stored in a seperate DLL? If so, maybe that DLL cannot be found.
0
 
doug5516Author Commented:
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
 
richard_hughesCommented:
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
 
doug5516Author Commented:
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
 
richard_hughesCommented:
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
 
doug5516Author Commented:
Did not mean to close it.
0
 
richard_hughesCommented:
How is the status of this error?
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 9
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now