Skip to main content
added 576 characters in body
Source Link
David Gouveia
  • 25k
  • 5
  • 89
  • 127

The word deserializing on your error message tipped me off - that wasn't supposed to appear in a normal scenario. That means it's a problem with the XNA content pipeline.

This happens because you were trying to build the XML through XNA's content pipeline. The solution is as simple as changing its Build Action property on the file from Compile to Content, and toggling the Copy to Output Directory property to true.

My old advice still applies though:

I don't think you should be adding whitespace to your data as a way to indent and make your XML look better, since they're not part of the data you're trying to store. This will force you to trim it when you read the data back, which is unnecessary in my opinion.

I think you should get rid of the tabs altogether, and possibly choose another character to act as the line separator (e.g. instead of using "\n" use a normal " " space).


Edit

i think i might know what it is that is causing the issue. For some reason it seems, compiling the XML into the game, it doesn't like the ',' thats is separating the values. Changing that it works :O. Unsure why its so fussy?

I am guessing that maybe your content writer is still doing a split by " " and then writing it in that way to the stream, but since you're now separating your values by "," it's not written correctly. So when deserializing, the ReadObject method is expecting a list of rectangles, but finds something else and fails.

Add your content reader and writer to your post if you need help figuring that out, but it really should be just a matter of keeping both with sync with each other and with the file format.


Edit 2

By the way, this doesn't look right:

anim.Rect = new List<Rectangle>();
anim.Rect = (List<Rectangle>)input.ReadObject<List<Rectangle>>();

You probably only need the second line. You're creating a new list and then overwriting it immediately. Not that it doesn't work, but is wasteful.

The word deserializing on your error message tipped me off - that wasn't supposed to appear in a normal scenario. That means it's a problem with the XNA content pipeline.

This happens because you were trying to build the XML through XNA's content pipeline. The solution is as simple as changing its Build Action property on the file from Compile to Content, and toggling the Copy to Output Directory property to true.

My old advice still applies though:

I don't think you should be adding whitespace to your data as a way to indent and make your XML look better, since they're not part of the data you're trying to store. This will force you to trim it when you read the data back, which is unnecessary in my opinion.

I think you should get rid of the tabs altogether, and possibly choose another character to act as the line separator (e.g. instead of using "\n" use a normal " " space).


Edit

i think i might know what it is that is causing the issue. For some reason it seems, compiling the XML into the game, it doesn't like the ',' thats is separating the values. Changing that it works :O. Unsure why its so fussy?

I am guessing that maybe your content writer is still doing a split by " " and then writing it in that way to the stream, but since you're now separating your values by "," it's not written correctly. So when deserializing, the ReadObject method is expecting a list of rectangles, but finds something else and fails.

The word deserializing on your error message tipped me off - that wasn't supposed to appear in a normal scenario. That means it's a problem with the XNA content pipeline.

This happens because you were trying to build the XML through XNA's content pipeline. The solution is as simple as changing its Build Action property on the file from Compile to Content, and toggling the Copy to Output Directory property to true.

My old advice still applies though:

I don't think you should be adding whitespace to your data as a way to indent and make your XML look better, since they're not part of the data you're trying to store. This will force you to trim it when you read the data back, which is unnecessary in my opinion.

I think you should get rid of the tabs altogether, and possibly choose another character to act as the line separator (e.g. instead of using "\n" use a normal " " space).


Edit

i think i might know what it is that is causing the issue. For some reason it seems, compiling the XML into the game, it doesn't like the ',' thats is separating the values. Changing that it works :O. Unsure why its so fussy?

I am guessing that maybe your content writer is still doing a split by " " and then writing it in that way to the stream, but since you're now separating your values by "," it's not written correctly. So when deserializing, the ReadObject method is expecting a list of rectangles, but finds something else and fails.

Add your content reader and writer to your post if you need help figuring that out, but it really should be just a matter of keeping both with sync with each other and with the file format.


Edit 2

By the way, this doesn't look right:

anim.Rect = new List<Rectangle>();
anim.Rect = (List<Rectangle>)input.ReadObject<List<Rectangle>>();

You probably only need the second line. You're creating a new list and then overwriting it immediately. Not that it doesn't work, but is wasteful.

added 576 characters in body
Source Link
David Gouveia
  • 25k
  • 5
  • 89
  • 127

The word deserializing on your error message tipped me off - that wasn't supposed to appear in a normal scenario. That means it's a problem with the XNA content pipeline.

This happens because you were trying to build the XML through XNA's content pipeline. The solution is as simple as changing its Build Action property on the file from Compile to Content, and toggling the Copy to Output Directory property to true.

My old advice still applies though:

I don't think you should be adding whitespace to your data as a way to indent and make your XML look better, since they're not part of the data you're trying to store. This will force you to trim it when you read the data back, which is unnecessary in my opinion.

I think you should get rid of the tabs altogether, and possibly choose another character to act as the line separator (e.g. instead of using "\n" use a normal " " space).


Edit

i think i might know what it is that is causing the issue. For some reason it seems, compiling the XML into the game, it doesn't like the ',' thats is separating the values. Changing that it works :O. Unsure why its so fussy?

I am guessing that maybe your content writer is still doing a split by " " and then writing it in that way to the stream, but since you're now separating your values by "," it's not written correctly. So when deserializing, the ReadObject method is expecting a list of rectangles, but finds something else and fails.

The word deserializing on your error message tipped me off - that wasn't supposed to appear in a normal scenario. That means it's a problem with the XNA content pipeline.

This happens because you were trying to build the XML through XNA's content pipeline. The solution is as simple as changing its Build Action property on the file from Compile to Content, and toggling the Copy to Output Directory property to true.

My old advice still applies though:

I don't think you should be adding whitespace to your data as a way to indent and make your XML look better, since they're not part of the data you're trying to store. This will force you to trim it when you read the data back, which is unnecessary in my opinion.

I think you should get rid of the tabs altogether, and possibly choose another character to act as the line separator (e.g. instead of using "\n" use a normal " " space).

The word deserializing on your error message tipped me off - that wasn't supposed to appear in a normal scenario. That means it's a problem with the XNA content pipeline.

This happens because you were trying to build the XML through XNA's content pipeline. The solution is as simple as changing its Build Action property on the file from Compile to Content, and toggling the Copy to Output Directory property to true.

My old advice still applies though:

I don't think you should be adding whitespace to your data as a way to indent and make your XML look better, since they're not part of the data you're trying to store. This will force you to trim it when you read the data back, which is unnecessary in my opinion.

I think you should get rid of the tabs altogether, and possibly choose another character to act as the line separator (e.g. instead of using "\n" use a normal " " space).


Edit

i think i might know what it is that is causing the issue. For some reason it seems, compiling the XML into the game, it doesn't like the ',' thats is separating the values. Changing that it works :O. Unsure why its so fussy?

I am guessing that maybe your content writer is still doing a split by " " and then writing it in that way to the stream, but since you're now separating your values by "," it's not written correctly. So when deserializing, the ReadObject method is expecting a list of rectangles, but finds something else and fails.

deleted 1366 characters in body
Source Link
David Gouveia
  • 25k
  • 5
  • 89
  • 127

I also suspected the "\t" and "\n" at first but then decidedThe word deserializing on your error message tipped me off - that wasn't supposed to runappear in a test on my side, and they didn't cause anynormal scenario. That means it's a problem with the XNA content pipeline. Nonetheless,

This happens because you should try replacing them with other characters justwere trying to be safebuild the XML through XNA's content pipeline. The solution is as simple as changing its Build Action property on the file from Compile to Content, and see if it makes a differencetoggling the Copy to Output Directory property to true.

My old advice still applies though:

I also don't think you should be using those charactersadding whitespace to your data as a way to indent and make your XML look better, since they're not part of the data you're trying to store. This will force you to trim it when you read the data back, which is unnecessary in my opinion. 

I think you should get rid of the tabs altogether, and possibly choose another character to act as the line separator (e.g. instead of using "\n" use a normal " " space).

Here's my test code which I created trying to emulate your problem. Try running it and see if there's any problem, because here it works okay:

using System;
using System.Text;
using System.Xml.Linq;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create some text
            StringBuilder builder = new StringBuilder();
            builder.Append("\n");
            builder.Append("\t0,0\n");
            builder.Append("\t1,1\n");
            builder.Append("\t2,2\n");
            builder.Append("\t");

            // Create XML and Save it
            XDocument document = new XDocument(
                new XElement("Root", 
                    new XElement("Child1", builder.ToString()),
                    new XElement("Child2", builder.ToString())
                )
            );
            document.Save("test.xml");
            
            // Load XML and Present it
            document = XDocument.Load("test.xml");
            Console.WriteLine(document.Element("Root").Element("Child1").Value);
            Console.WriteLine(document.Element("Root").Element("Child2").Value);
            Console.ReadKey();
        }
    }
}

Which resulted in the following XML:

<?xml version="1.0" encoding="utf-8"?>
<Root>
  <Child1>
    0,0
    1,1
    2,2
    </Child1>
  <Child2>
    0,0
    1,1
    2,2
    </Child2>
</Root>

I also suspected the "\t" and "\n" at first but then decided to run a test on my side, and they didn't cause any problem. Nonetheless, you should try replacing them with other characters just to be safe and see if it makes a difference.

I also don't think you should be using those characters as a way to indent and make your XML look better, since they're not part of the data you're trying to store. I think you should get rid of the tabs altogether, and possibly choose another character to act as the line separator (e.g. instead of using "\n" use a normal " " space).

Here's my test code which I created trying to emulate your problem. Try running it and see if there's any problem, because here it works okay:

using System;
using System.Text;
using System.Xml.Linq;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create some text
            StringBuilder builder = new StringBuilder();
            builder.Append("\n");
            builder.Append("\t0,0\n");
            builder.Append("\t1,1\n");
            builder.Append("\t2,2\n");
            builder.Append("\t");

            // Create XML and Save it
            XDocument document = new XDocument(
                new XElement("Root", 
                    new XElement("Child1", builder.ToString()),
                    new XElement("Child2", builder.ToString())
                )
            );
            document.Save("test.xml");
            
            // Load XML and Present it
            document = XDocument.Load("test.xml");
            Console.WriteLine(document.Element("Root").Element("Child1").Value);
            Console.WriteLine(document.Element("Root").Element("Child2").Value);
            Console.ReadKey();
        }
    }
}

Which resulted in the following XML:

<?xml version="1.0" encoding="utf-8"?>
<Root>
  <Child1>
    0,0
    1,1
    2,2
    </Child1>
  <Child2>
    0,0
    1,1
    2,2
    </Child2>
</Root>

The word deserializing on your error message tipped me off - that wasn't supposed to appear in a normal scenario. That means it's a problem with the XNA content pipeline.

This happens because you were trying to build the XML through XNA's content pipeline. The solution is as simple as changing its Build Action property on the file from Compile to Content, and toggling the Copy to Output Directory property to true.

My old advice still applies though:

I don't think you should be adding whitespace to your data as a way to indent and make your XML look better, since they're not part of the data you're trying to store. This will force you to trim it when you read the data back, which is unnecessary in my opinion. 

I think you should get rid of the tabs altogether, and possibly choose another character to act as the line separator (e.g. instead of using "\n" use a normal " " space).

Source Link
David Gouveia
  • 25k
  • 5
  • 89
  • 127
Loading