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?

1 Answer 1


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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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