Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My winforms app gets an IWorkspaceName from an IDatasetName via the GxObject selected in a GxDialog. I want to pass it across to a worker thread for opening.

I know how to write multithreaded arcobjects code - particularly the need to create the workspace factory class on the worker thread but my app makes no assumptions as to the type of workspace factory. I've considered passing it as a serialized xml string, but the documentation seems strangely vague on this topic. Does anyone have code to do this?

On preview,

I'm asking much the same as this question. Has anyone cracked the xml serialization / deserialization? It seems the simplest way to go or is there a better way?

share|improve this question
up vote 6 down vote accepted

See my example code below, it will enable you to deserialize instance of IWorkspaceName on the other thread from the XML produced by the serialization method.

It can be easily modified to allow serialization and deserialization of any ArcObject which implements ESRI.ArcGIS.esriSystem.IXMLSerialize.

    private static string GetWorkspaceNameAsXmlString(IWorkspaceName workspaceName)
        if (workspaceName == null) throw new ArgumentNullException("workspaceName");

        var xmlStream = new XMLStreamClass();
        var xmlWriter = new XMLWriterClass();
        var xmlSerializer = new XMLSerializerClass();

        xmlSerializer.WriteObject(xmlWriter, null, null, string.Empty, string.Empty, workspaceName);

        return xmlStream.SaveToString();

    private static IWorkspaceName GetWorkspaceNameFromXmlString(string xml)
        if (xml == null) throw new ArgumentNullException("xml");

        var xmlStream = new XMLStreamClass();
        var xmlReader = new XMLReaderClass();
        var xmlSerializer = new XMLSerializerClass();


        return xmlSerializer.ReadObject(xmlReader, null, null) as IWorkspaceName;
share|improve this answer
Thanks. Exactly what I needed. – nef001 Nov 9 '10 at 23:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.