XNA Creators Club Online
Page 1 of 2 (27 items) 1 2 Next >
Sort Posts: Previous Next

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

    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 In reply to

    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 In reply to

    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 In reply to

    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
    1. In my ContentPipeline project, I created a PlanetSurfaceContentWriter and a PlanetSurfaceContent class.
    2. In the Content class, it's just a basic class with 3 string fields.
    3. In the ContentWriter class, I selected "Content Writer" when I clicked "Add New" and the template filled out almost everything to start.
    4. I changed the "using TWrite" code to "using TWrite=PlanetSurfaceContent" (with namespace, etc.)
    5. Next, I updated the output.write code and the function that stores the ContentReader class.

    Step 2: Content Reader coding
    1. In my GameLibrary project, I created a PlanetSurfaceContentReader (using the ContentReader template) and a PlanetSurfaceData class.
    2. In the PlanetSurfaceData class, I copied the 3 fields from the PlanetSurfaceContentClass.
    3. In the Reader, I updated the "using TRead" to using PlanetSurfaceData (not content).
    4. 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
    1. 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 In reply to

    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 In reply to

    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 In reply to

    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 In reply to

    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 In reply to

    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 In reply to

    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 In reply to

    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 In reply to

    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