Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7699687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:32:12+00:00 2026-05-31T22:32:12+00:00

I’m having a problem with the c# XML serialization system it’s throws an Ambigus

  • 0

I’m having a problem with the c# XML serialization system it’s throws an Ambigus exception,

There was an error generating the XML document.

Now i have a Class that contains refferences to other classes and arrays of the other classes

E.G

namespace P2PFileLayout
{
    public class p2pfile
    {
        public FileList FileList;
        public StatusServer StatusServer;
        public String Hash;
    }
}
namespace P2PFileLayout.parts
{
    public class StatusServer
    {
        public Auth Auth;
        public Servers Servers;
    }
    public class Servers
    {
        public Server[] Server;
    }
    public class Server
    {
        public bool AuthRequired = false;
        public string Address;
    }
    public class Files
    {
        public File[] File;
    }
    public class File
    {
        public string FileName = "";
        public int BlockSize = 0;
        public int BlockCount = 0;
    }
    public class Directory
    {
        public string Name;
        public Files Files;
        public Directory[] Dir;
    }
    public class Auth
    {
        public AuthServer[] AuthServer;
    }
    public class FileList
    {
        public Files Files;
        public Directory[] Directory;
    }
}

My Example data

        // create the test file
        testFile = new p2pfile();

        // create a fake fileList
        testFile.FileList = new P2PFileLayout.parts.FileList();
        testFile.FileList.Directory = new P2PFileLayout.parts.Directory[1];
        testFile.FileList.Directory[0] = new P2PFileLayout.parts.Directory();
        testFile.FileList.Directory[0].Name = "testFolder";
        testFile.FileList.Directory[0].Files = new P2PFileLayout.parts.Files();
        testFile.FileList.Directory[0].Files.File = new P2PFileLayout.parts.File[2];
        testFile.FileList.Directory[0].Files.File[0] = new P2PFileLayout.parts.File();
        testFile.FileList.Directory[0].Files.File[0].FileName = "test.txt";
        testFile.FileList.Directory[0].Files.File[0].BlockSize = 64;
        testFile.FileList.Directory[0].Files.File[0].BlockCount = 1;
        testFile.FileList.Directory[0].Files.File[1] = new P2PFileLayout.parts.File();
        testFile.FileList.Directory[0].Files.File[1].FileName = "test2.txt";
        testFile.FileList.Directory[0].Files.File[1].BlockSize = 64;
        testFile.FileList.Directory[0].Files.File[1].BlockCount = 1;

        // create a fake status server
        testFile.StatusServer = new P2PFileLayout.parts.StatusServer();
        testFile.StatusServer.Servers = new P2PFileLayout.parts.Servers();
        testFile.StatusServer.Servers.Server = new P2PFileLayout.parts.Server[1];
        testFile.StatusServer.Servers.Server[0] = new P2PFileLayout.parts.Server();
        testFile.StatusServer.Servers.Server[0].Address = "http://localhost:8088/list.php";

        // create a file hash (real)
        HashGenerator.P2PHash hashGen = new HashGenerator.P2PHash();
        testFile.Hash = hashGen.getHash();

        treeView1.Nodes.Add(new TreeNode("Loading..."));

        Classes.CreateTreeView ctv = new Classes.CreateTreeView();
        ctv.BuildTreeView(testFile.FileList, treeView1);
        treeView1.AfterCheck += new TreeViewEventHandler(treeView1_AfterCheck);

Now that is not as complicated as mine in terms of dept as my i loop objects so dir has support for more dirs but thats just an example

Then i’m serializing to a string var as i want to do a little more than just serialize it but here is my serialization

private string ToXml(object Obj, System.Type ObjType)
        {
            // instansiate the xml serializer object
            XmlSerializer ser = new XmlSerializer(ObjType);
            // create a memory stream for XMLTextWriter to use
            MemoryStream memStream = new MemoryStream();
            // create an XML writer using our memory stream
            XmlTextWriter xmlWriter = new XmlTextWriter(memStream, Encoding.UTF8);
            // write the object though the XML serializer method using the W3C namespaces
            ser.Serialize(xmlWriter, Obj);
            // close the XMLWriter
            xmlWriter.Close();
            // close the memoryStream
            memStream.Close();
            // get the string from the memory Stream
            string xml = Encoding.UTF8.GetString(memStream.GetBuffer());
            // remove the stuff before the xml code we care about
            xml = xml.Substring(xml.IndexOf(Convert.ToChar(60)));
            // clear any thing at the end of the elements we care about
            xml = xml.Substring(0, (xml.LastIndexOf(Convert.ToChar(62)) + 1));
            // return the XML string
            return xml;
        }

Can any one see why this is not working or any clues as to why it would not work normally

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:32:13+00:00Added an answer on May 31, 2026 at 10:32 pm

    Why are you doing it manually?
    What about this approach?
    http://support.microsoft.com/kb/815813

    Test test = new Test() { Test1 = "1", Test2 = "3" };
    System.Xml.Serialization.XmlSerializer x = new   System.Xml.Serialization.XmlSerializer(test.GetType());
    MemoryStream ms = new MemoryStream();
    x.Serialize(ms, test);
    ms.Position = 0;
    StreamReader sr = new StreamReader(ms);
    string xml = sr.ReadToEnd();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have just tried to save a simple *.rtf file with some websites and
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.