Help with IntermediateSerializer

Hello!

I’m having some problems with the new IntermediateSerializer. Whenever I’m serializing to a file I get the error:

An unhandled exception of type ‘System.NotImplementedException’ occurred in MonoGame.Framework.Content.Pipeline.dll

Additional information: Unhandled primitive type System.Int32!

The class im serializing:

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Microsoft.Xna.Framework;

namespace Microsoft.Xna.Framework.Graphics
{

    public class Polygon
    {
        private List<Vector2> points = new List<Vector2>();
        private List<Vector2> edges = new List<Vector2>();

        public Polygon()
        {
        }

        private float rotationAngle = 0;
        /// <summary>
        /// Rotate a point around a center point
        /// </summary>
        /// <param name="point">point to be rotated</param>
        /// <param name="centerPoint">center point to rotate around</param>
        /// <param name="angle">angle to rotate to</param>
        /// <returns></returns>
        private Vector2 RotatePoint(Vector2 point, Vector2 centerPoint, float rotationAngle)
        {
            Vector2 translated = point - centerPoint;
            Vector2 rotated = new Vector2
            {
                X = translated.X * (float)Math.Cos(rotationAngle) - translated.Y * (float)Math.Sin(rotationAngle),
                Y = translated.X * (float)Math.Sin(rotationAngle) + translated.Y * (float)Math.Cos(rotationAngle)
            };
            return rotated + centerPoint;
        }

        public void BuildEdges()
        {
            Vector2 p1;
            Vector2 p2;
            edges.Clear();
            for (int i = 0; i < points.Count; i++)
            {
                p1 = points[i];
                if (i + 1 >= points.Count)
                {
                    p2 = points[0];
                }
                else
                {
                    p2 = points[i + 1];
                }

                edges.Add(RotatePoint(p2 - p1, Center, RotationAngle));
            }
        }

        public List<Vector2> Edges
        {
            get { return edges; }
        }

        public List<Vector2> Points
        {
            get { return points; }
        }

        public float RotationAngle
        {
            get { return rotationAngle; }
            set { rotationAngle = value; }
        }

        public Vector2 Center
        {
            get
            {
                float totalX = 0;
                float totalY = 0;
                for (int i = 0; i < points.Count; i++)
                {
                    totalX += points[i].X;
                    totalY += points[i].Y;
                }

                return new Vector2(totalX / (float)points.Count, totalY / (float)points.Count);
            }
        }

        public void Offset(Vector2 v)
        {
            Offset(v.X, v.Y);
        }

        public void Offset(float x, float y)
        {
            for (int i = 0; i < points.Count; i++)
            {
                Vector2 p = points[i];
                points[i] = new Vector2(p.X + x, p.Y + y);
            }
        }

        public override string ToString()
        {
            string result = "";

            for (int i = 0; i < points.Count; i++)
            {
                if (result != "") result += " ";
                result += "{" + (int)Math.Round(points[i].X) + ", " + (int)Math.Round(points[i].Y) + "}";
            }

            return result;
        }

        public void Draw(SpriteBatch spriteBatch, Texture2D texture)
        {
            Vector2 p1;
            Vector2 p2;
            edges.Clear();
            for (int i = 0; i < points.Count; i++)
            {
                p1 = RotatePoint(Points[i], Center, RotationAngle);
                if (i + 1 >= points.Count)
                {
                    p2 = RotatePoint(Points[0], Center, RotationAngle);
                }
                else
                {
                    p2 = RotatePoint(Points[i + 1], Center, RotationAngle);
                }

                spriteBatch.DrawLine(texture, new Vector2(p1.X, p1.Y), new Vector2(p2.X, p2.Y), Color.White, 3);
            }
        }
       
        // Check if polygon A is going to collide with polygon B for the given velocity
        public CollisionResult CheckCollision(Polygon polygonToCheck, Vector2 velocity)
        {
            Polygon polygonA = this;
            Polygon polygonB = polygonToCheck;

            CollisionResult result = new CollisionResult();
            result.Intersect = true;
            result.WillIntersect = true;

            int edgeCountA = polygonA.Edges.Count;
            int edgeCountB = polygonB.Edges.Count;
            float minIntervalDistance = float.PositiveInfinity;
            Vector2 translationAxis = new Vector2();
            Vector2 edge;

            // Loop through all the edges of both polygons
            for (int edgeIndex = 0; edgeIndex < edgeCountA + edgeCountB; edgeIndex++)
            {
                if (edgeIndex < edgeCountA)
                {
                    edge = polygonA.Edges[edgeIndex];
                }
                else
                {
                    edge = polygonB.Edges[edgeIndex - edgeCountA];
                }

                // ===== 1. Find if the polygons are currently intersecting =====

                // Find the axis perpendicular to the current edge
                Vector2 axis = new Vector2(-edge.Y, edge.X);
                axis.Normalize();

                // Find the projection of the polygon on the current axis
                float minA = 0; float minB = 0; float maxA = 0; float maxB = 0;
                Project(axis, polygonA, ref minA, ref maxA);
                Project(axis, polygonB, ref minB, ref maxB);

                // Check if the polygon projections are currentlty intersecting
                if (IntervalDistance(minA, maxA, minB, maxB) > 0) result.Intersect = false;

                // ===== 2. Now find if the polygons *will* intersect =====

                // Project the velocity on the current axis
                velocity.Normalize();

                float velocityProjection = Vector2.Dot(axis, velocity);

                // Get the projection of polygon A during the movement
                if (velocityProjection < 0)
                {
                    minA += velocityProjection;
                }
                else
                {
                    maxA += velocityProjection;
                }

                // Do the same test as above for the new projection
                float intervalDistance = IntervalDistance(minA, maxA, minB, maxB);
                if (intervalDistance > 0) result.WillIntersect = false;

                // If the polygons are not intersecting and won't intersect, exit the loop
                if (!result.Intersect && !result.WillIntersect) break;

                // Check if the current interval distance is the minimum one. If so store
                // the interval distance and the current distance.
                // This will be used to calculate the minimum translation Vector2
                intervalDistance = Math.Abs(intervalDistance);
                if (intervalDistance < minIntervalDistance)
                {
                    minIntervalDistance = intervalDistance;
                    translationAxis = axis;

                    Vector2 d = polygonA.Center - polygonB.Center;
                    d.Normalize();
                    if (Vector2.Dot(d, translationAxis) < 0) translationAxis = -translationAxis;
                }
            }

            // The minimum translation Vector2 can be used to push the polygons appart.
            // First moves the polygons by their velocity
            // then move polygonA by MinimumTranslationVector2.
            if (result.WillIntersect) result.MinimumTranslationVector2 = translationAxis * minIntervalDistance;

            return result;
        }

        // Calculate the distance between [minA, maxA] and [minB, maxB]
        // The distance will be negative if the intervals overlap
        private float IntervalDistance(float minA, float maxA, float minB, float maxB)
        {
            if (minA < minB)
            {
                return minB - maxA;
            }
            else
            {
                return minA - maxB;
            }
        }

        // Calculate the projection of a polygon on an axis and returns it as a [min, max] interval
        private void Project(Vector2 axis, Polygon polygon, ref float min, ref float max)
        {
            // To project a point on an axis use the dot product
            Vector2 point0 = polygon.Points[0];
            point0.Normalize();

            float d = Vector2.Dot(axis, point0);
            min = d;
            max = d;
            for (int i = 0; i < polygon.Points.Count; i++)
            {
                Vector2 point = polygon.points[i];
                point.Normalize();

                d = Vector2.Dot(point, axis);
                if (d < min)
                {
                    min = d;
                }
                else
                {
                    if (d > max)
                    {
                        max = d;
                    }
                }
            }
        }

        // Structure that stores the results of the PolygonCollision function
        public struct CollisionResult
        {
            public bool WillIntersect; // Are the polygons going to intersect forward in time?
            public bool Intersect; // Are the polygons currently intersecting
            public Vector2 MinimumTranslationVector2; // The translation to apply to polygon A to push the polygons appart.
        }
    }
}

Code to serialize:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate;

namespace Microsoft.Xna.Framework
{
    public static class XnaSerializer
    {
        public static void Serialize<T>(string filename, T data)
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;

            using (XmlWriter writer = XmlWriter.Create(filename, settings))
            {
              IntermediateSerializer.Serialize<T>(writer, data, null);                
            }
        }

        public static T Deserialize<T>(string filename)
        {
            T data;

            using (FileStream stream = new FileStream(filename, FileMode.Open))
            {
                using (XmlReader reader = XmlReader.Create(stream))
                {
                    data = IntermediateSerializer.Deserialize<T>(reader, null);
                }
            }

            return data;
        }
    }
}

Now, I’m trying to understand monogame, but it has been so confusing. At first I used the nuget package, but it had old versions and even different versions from each other so it wouldn’t even build. Then I used the windows installer, however that one is missing the tools folder. My most current attempt has been downloading the source files and using the ddls from the project, where both MonoGame.Framework.dll and MonoGame.Framework.Content.Pipeline.dll are present.

So far so good.

However am I really using the monogame IntermediateSerializer? Im confused about the namespaces that are still called Microsoft.Xna…ect.

I tried looking up the monograme namespaces but nothing came up on IntermediateSerializer.

So, am I mixing stuff up, or why am I getting this weird error?