|
|
Error while deserializing intermediate XML, Cannot find type "Library.Map".
Last post 04-23-2008, 5:07 PM by ButterKnife. 26 replies.
-
04-15-2008, 5:25 PM |
-
ButterKnife
-
-
-
Joined on 03-24-2008
-
-
Posts 64
-
-
|
Error while deserializing intermediate XML, Cannot find type "Library.Map".
Hi, I need help with deserializing an XML file: There was an error while deserializing intermediate XML. Cannot find type "Library.Map". The library is referenced and it works when I try to make some 'Map class'-es, but in the edited XML file I created I get the above error. How do I fix it? - I think that letting the "public static class XMLContentWriter" class do the work will fix it but how do I write an XML file with it?
Thanks in advance, Tal A.
There are 10 types of people in the world: Those who know binary and those who dont.
|
|
-
04-16-2008, 7:58 AM |
-
ButterKnife
-
-
-
Joined on 03-24-2008
-
-
Posts 64
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
Maybe I need to say that more clearly. I know that "Library.Map m = content.Load<Library.Map>(@"XML/Maps");" will 'read' an existing XML file into a new Map variable, but how do I write to a file that not even exist yet? (Create an XML file and write some data into it)
There are 10 types of people in the world: Those who know binary and those who dont.
|
|
-
04-17-2008, 1:53 PM |
-
ButterKnife
-
-
-
Joined on 03-24-2008
-
-
Posts 64
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
Please help!
There are 10 types of people in the world: Those who know binary and those who dont.
|
|
-
04-17-2008, 6:58 PM |
-
Jim W
-
-
-
Joined on 02-21-2008
-
San Diego
-
Posts 176
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
Ok, I just went through this for the first time today. I ran into the same problem that you have and here's how I fixed it. First, I downloaded the Authoring-Particle-Systems-Using-XML-and-the-Content-Pipeline tutorial to see how the experts do it. (Okay, that wasn't first. I actually tried it myself but then ran into the same error that you got.) Next, I went through that code and then grokked the XML content technqiue. I had assumed wrong in how it worked. Here's how I got mine to work: I have 3 projects: GameLibrary, ContentPipeline, and Game. I will be loading data named "PlanetSurface" that stores 3 strings (planet name, name of texture for surface, and name of texture for skydome). Step 1: Content Pipeline coding - In my ContentPipeline project, I created a PlanetSurfaceContentWriter and a PlanetSurfaceContent class.
- In the Content class, it's just a basic class with 3 string fields.
- In the ContentWriter class, I selected "Content Writer" when I clicked "Add New" and the template filled out almost everything to start.
- I changed the "using TWrite" code to "using TWrite=PlanetSurfaceContent" (with namespace, etc.)
- Next, I updated the output.write code and the function that stores the ContentReader class.
Step 2: Content Reader coding - In my GameLibrary project, I created a PlanetSurfaceContentReader (using the ContentReader template) and a PlanetSurfaceData class.
- In the PlanetSurfaceData class, I copied the 3 fields from the PlanetSurfaceContentClass.
- In the Reader, I updated the "using TRead" to using PlanetSurfaceData (not content).
- In the Reader, I updated code to do the input.Read, etc. and assign my variables after creating a new instance, and then return that instance, etc.
Step 3: Game coding - Finally, I create my XML file that looks like this:
<?xml version="1.0" encoding="utf-8" ?> <XnaContent> <Asset Type="GameEngine.ContentPipeline.PlanetSurface.PlanetSurfaceMapContent"> <TerrainAssetName>Models\\Heightmaps\\DemoMap2\\heightmap</TerrainAssetName> <SkyAssetName>Models\\Skys\\Space</SkyAssetName> <Name>Test Planet</Name> </Asset> </XnaContent> In my game, I simply use "currentSceneData = contentManager.Load<PlanetSurfaceMapData>(@"Xml\Planets\TestPlanet");" Then it works :) This was very hastily written, so I might do a better article later today or tonight and blog it. I had thought that it would have been a bit easier, but now I understand the difference between using this and serialization.
----------------------------------------------- Jim Welch
|
|
-
04-18-2008, 1:48 AM |
-
ButterKnife
-
-
-
Joined on 03-24-2008
-
-
Posts 64
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
But how do I write the data for the first time (when I dont even have a file)? If I must have a file (even empty) for the first time writting to it, how can I do a general empty file that will not generate any error on the "Type" attribute?
I'm going to a 4-day trip, so you will not hear from me soon..
Thanks In Advance, Tal A.
There are 10 types of people in the world: Those who know binary and those who dont.
|
|
-
04-18-2008, 2:05 AM |
-
Jim W
-
-
-
Joined on 02-21-2008
-
San Diego
-
Posts 176
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
If you download the sample above, there's sample code for how to write an intermediate serializer. If you modify that and just put your class there, it will write an empty XnaContent XML document for you. That example code is in the HTML document in the sample's ZIP file (at the end of the document). The code will look something like this: (just replace MyClass with whatever your class name is). using System.Xml; using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate;
namespace MyXmlCreatorTest { public static class Program { public static void Main() { object testValue = new MyClass(); XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Indent = true;
using (XmlWriter xmlWriter = XmlWriter.Create(“test.xml”, xmlSettings)) { IntermediateSerializer.Serialize(xmlWriter, testValue , null); } } } }
----------------------------------------------- Jim Welch
|
|
-
04-22-2008, 6:48 AM |
-
ButterKnife
-
-
-
Joined on 03-24-2008
-
-
Posts 64
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
Hi, I'm back.. (after a four days trip) I can write now the data into a file but the problem from the first post is still there. Why does it happen and how can I fix it? ButterKnife:Hi, I need help with deserializing an XML file: There was an error while deserializing intermediate XML. Cannot find type "Library.Map". The library is referenced and it works when I try to make some 'Map class'-es, but in the edited XML file I created I get the above error. How do I fix it? - I think that letting the "public static class XMLContentWriter" class do the work will fix it but how do I write an XML file with it?
Thanks in advance, Tal A.
There are 10 types of people in the world: Those who know binary and those who dont.
|
|
-
04-22-2008, 11:00 AM |
-
Jim W
-
-
-
Joined on 02-21-2008
-
San Diego
-
Posts 176
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
Where did you write the code for your content reader? Deserializing needs the reader not the writer, so make sure that DLL is referenced from your content project. Can you post the XML element of "Asset Type" and the line of code where you declare your content reader class?
----------------------------------------------- Jim Welch
|
|
-
04-22-2008, 11:57 AM |
-
ButterKnife
-
-
-
Joined on 03-24-2008
-
-
Posts 64
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
1. <?xml version="1.0" encoding="utf-8"?> <XnaContent> <Asset Type="Library.Map"> <Name>Test_1</Name> <Gravity>9.89</Gravity> </Asset> </XnaContent> 2. public class MapContentReader : ContentTypeReader<Map> { protected override Map Read(ContentReader input, Map existingInstance) { Map map = new Map(); map.Name = input.ReadString(); map.Gravity = (float)input.ReadDouble(); map.SetPhysics(); return map; } } I hope somone can help me using this..
There are 10 types of people in the world: Those who know binary and those who dont.
|
|
-
04-22-2008, 12:01 PM |
-
Jim W
-
-
-
Joined on 02-21-2008
-
San Diego
-
Posts 176
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
Does the XML file produced from running the intermediate serializer look any different from the above XML file? That looks almost identical to what I have in my app and it works here, so there must be something really small and easy to miss somewhere.
----------------------------------------------- Jim Welch
|
|
-
04-22-2008, 12:10 PM |
-
ButterKnife
-
-
-
Joined on 03-24-2008
-
-
Posts 64
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
I copied and the pasted here.. It's the same.
There are 10 types of people in the world: Those who know binary and those who dont.
|
|
-
04-22-2008, 12:30 PM |
-
Jim W
-
-
-
Joined on 02-21-2008
-
San Diego
-
Posts 176
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
Is there anyway you can break out some of your class files and projects into a simple set of projects that only has these classes in it for testing? And then upload that file somewhere so others can download it and look at your project files?
----------------------------------------------- Jim Welch
|
|
-
04-22-2008, 12:43 PM |
-
ButterKnife
-
-
-
Joined on 03-24-2008
-
-
Posts 64
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
I'll do it in a minute, where can I upload it to? (if posible without subscribing)
There are 10 types of people in the world: Those who know binary and those who dont.
|
|
-
04-22-2008, 12:49 PM |
-
Jim W
-
-
-
Joined on 02-21-2008
-
San Diego
-
Posts 176
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
I'ved used YouSendIt several times. You can just send it to yourself and then post the URL contained in the email to the forums. I'm sure there's other sites out there, but that's worked for me in the past.
----------------------------------------------- Jim Welch
|
|
-
04-22-2008, 1:38 PM |
-
ButterKnife
-
-
-
Joined on 03-24-2008
-
-
Posts 64
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
YouSandIt keep telling me that my computer is a virus factory so I used uploading.com, seems it does the work.. Link. Note: It gives a diffrent error msg: "file not found", but I'm sure that after solving that problem it will give the error I mentioned.
There are 10 types of people in the world: Those who know binary and those who dont.
|
|
-
04-22-2008, 1:58 PM |
-
Jim W
-
-
-
Joined on 02-21-2008
-
San Diego
-
Posts 176
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
Well, your XML files look good, but I don't know if it's your broken out project or not, but there's one big issue here. You are writing out XML files and then trying to read those XML files. That's not how XnaContent XML documents work. You write the XnaContent XML files, then the ContentPipeline processes the XML files into XNB files, then you Load/Read XNB files from within your game (you don't read the written XML files). You need to add the XML file to your game's content sub-project, then just read it without using the asset name and not the filename (usually just the filename without extension). Do you have an associated XNB file in your game's output's content folder, somewhere like <my game dir>\bin\x86\Debug\Content\xFile.xnb? If so, then doing a Content.Load<Library.Map>("xfile") should work. If you just need to write/read XML files without using the XnaContent XML files, then you can use just serialization/deserialization of classes, etc. There's a couple benefits of using XNB files such as compression and that it's not XML (clear text), but it requires that you build the XML files into XNB files.
----------------------------------------------- Jim Welch
|
|
-
04-22-2008, 2:19 PM |
-
ButterKnife
-
-
-
Joined on 03-24-2008
-
-
Posts 64
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
well.. I think I should at least try the two methods so I can decide.. to achive that I need answers to the following questions: 1. How do I make an .xnb format file? 2. hoe do I use the deserialization?
Thanks in advance
There are 10 types of people in the world: Those who know binary and those who dont.
|
|
-
04-22-2008, 2:49 PM |
-
Jim W
-
-
-
Joined on 02-21-2008
-
San Diego
-
Posts 176
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
ButterKnife: 1. How do I make an .xnb format file?
If you add your XnaContent XML file to your game's content's project, then when you build your game then the XML files will automatically get built to XNB files. This requires that you make all of your XML files before you build the game, so only design-time XML files can be turned into XNB like this, not during run-time. If you just create a new XNA game using the template, then you'll see a folder under your game root folder (in solution explorer) that says "Content". This will be a while folder (not yellow), just drag and drop or right-click and choose "Add" your XML file there. Then make sure to click on it to see it's properties in the property grid to make sure it lists the XNA content processor, etc. ButterKnife: 2. hoe do I use the deserialization?
You can just use the default .NET deserialization techniques. http://msdn2.microsoft.com/en-us/library/fa420a9y(VS.80).aspx
----------------------------------------------- Jim Welch
|
|
-
04-22-2008, 3:28 PM |
-
ButterKnife
-
-
-
Joined on 03-24-2008
-
-
Posts 64
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
It is still unsolved: in the XML file it says that the Library.Map can not be found..
Note: I created the file using the serialization technique and tried to read it with the .NET deserialization technique.
Edit: Additionly, I have another .xml file called keyboardSettings (KS.xml for short). The ContentPipeline make a KS.xnb, but not a xfile.xnb. Moreover, they have the same properties value (Build Action: Compile; Copy To Output Directory: Do not copy; Content Importer: XML Content - XNA Framework; Content Processor: No Processing Required).
There are 10 types of people in the world: Those who know binary and those who dont.
|
|
-
04-22-2008, 3:38 PM |
-
Jim W
-
-
-
Joined on 02-21-2008
-
San Diego
-
Posts 176
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
I think you are mixing techniques. You can't use Content.Load with serialized class files that are not XNB files. Can you post your serialization and deserialization techniques? If you use XNA content XML files, then you can't use .NET serialization or .NET deserialization techniques, you need to use Content.Load. If you use .NET serialization or .NET deserialization techniques, then you can't use XNA content XML files, you need to use just plain, old, standard XML documents, etc.
----------------------------------------------- Jim Welch
|
|
-
04-22-2008, 4:07 PM |
-
ButterKnife
-
-
-
Joined on 03-24-2008
-
-
Posts 64
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
I've done as you said: changed the xml file properties so it will be a regular file, but now I have a new error: {"נמצאה שגיאה במסמך XML (2, 2)."} It means "error found in document XML(2, 2).", the file content is: <?xml version="1.0" encoding="utf-8"?> <XnaContent> <Asset Type="Library.Map"> <Name>Test_1</Name> <FallPerTimeUnit>3</FallPerTimeUnit> <Gravity>1.07</Gravity> </Asset> </XnaContent>
I thought that the "(2, 2)" means "line 2, column 2" and deleted the "<XnaContent>" & "</XnaContent>" but it was for no use..
There are 10 types of people in the world: Those who know binary and those who dont.
|
|
-
04-22-2008, 4:20 PM |
-
Jim W
-
-
-
Joined on 02-21-2008
-
San Diego
-
Posts 176
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
The above file is not a regular XML file, it's a XnaContent XML file. If you want to use the standard .NET serialization/deserialization, then you should write out your class file as a seralized class XML document and use that. Then you won't be using any content readers or writers and you won't be using anything from the content pipeline, etc. here's a how to serialize link: http://support.microsoft.com/kb/815813XnaContent XML files are going to use XnaContent and Asset Type elements. If you just serialize your class it'll look something like: <?xml version="1.0" encoding="UTF8"?> <Map xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Name>Test_1</Name> <FallPerTimeUnit>3</FallPerTimeUnit> <Gravity>1.07</Gravity> </Map>
----------------------------------------------- Jim Welch
|
|
-
04-22-2008, 5:46 PM |
-
ButterKnife
-
-
-
Joined on 03-24-2008
-
-
Posts 64
-
-
|
Re: Error while deserializing intermediate XML, Cannot find type "Library.Map".
That is great! but I have one more question (for serialize): how do I make it write into a file? I know that the lines: x.Serialize(Console.Out, p); Console.WriteLine(); Console.ReadLine();
Returns serialized data as stream, and than paste it into a console. But how can I save the stream to a txt file instead?
There are 10 types of people in the world: Those who know binary and those who dont.
|
|
-
04-22-2008, 5:51 PM |
|
|