ThinkGeo.com    |     Documentation    |     Premium Support

GeoSerializer

I have been trying out the GeoSerializer feature and it worked well for single layers however I tried to use it to serialize a GeoCollection of three InMemoryFeatureLayers and got the following error:


System.ArgumentException was unhandled

  Message="Invalid name character in 'GeoCollection`1'. The '`' character, hexadecimal value 0x60, cannot be included in a name."

  Source="System.Xml"

  StackTrace:

       at System.Xml.XmlWellFormedWriter.CheckNCName(String ncname)

       at System.Xml.XmlWellFormedWriter.WriteStartElement(String prefix, String localName, String ns)

       at System.Xml.XmlWriter.WriteStartElement(String localName)

       at ThinkGeo.MapSuite.Core.XmlGeoSerializationFormatter.4xU=(GeoObjectNode 5BU=, XmlWriter 5RU=)

       at ThinkGeo.MapSuite.Core.XmlGeoSerializationFormatter.SaveCore(GeoObjectModel model, Stream stream)

       at ThinkGeo.MapSuite.Core.GeoSerializationFormatter.Save(GeoObjectModel model, Stream stream)

       at ThinkGeo.MapSuite.Core.GeoSerializer.Serialize(Object objectToSerialize, String targetPathFileName)

       at PTSimpleMapper.clsMapSupport.mergeRedline(WinformsMap& theMap) in C:\Users\Jonathan\Documents\Visual Studio 2008\Projects\simpleMapper\simpleMapper\clsMapSupport.cs:line 623

       at PTSimpleMapper.frmMap.mergeRedLines() in C:\Users\Jonathan\Documents\Visual Studio 2008\Projects\simpleMapper\simpleMapper\frmMap.cs:line 543

       at PTSimpleMapper.ctrlRedline.btnMerge_Click(Object sender, EventArgs e) in C:\Users\Jonathan\Documents\Visual Studio 2008\Projects\simpleMapper\simpleMapper\ctrlRedline.cs:line 61

       at System.Windows.Forms.Control.OnClick(EventArgs e)

       at System.Windows.Forms.Button.OnClick(EventArgs e)

       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

       at System.Windows.Forms.Control.WndProc(Message& m)

       at System.Windows.Forms.ButtonBase.WndProc(Message& m)

       at System.Windows.Forms.Button.WndProc(Message& m)

       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)

       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)

       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

       at System.Windows.Forms.Application.Run(Form mainForm)

       at PTSimpleMapper.Program.Main() in C:\Users\Jonathan\Documents\Visual Studio 2008\Projects\simpleMapper\simpleMapper\Program.cs:line 18

       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

       at System.Threading.ThreadHelper.ThreadStart()

  InnerException:


My code is:


 



            GeoSerializer redLineSerial = new GeoSerializer();
            GeoCollection<InMemoryFeatureLayer> annotationLayers = new GeoCollection<InMemoryFeatureLayer>();
            
            LayerOverlay emphasisOverlay = (LayerOverlay)theMap.Overlays[EMPHASIS_OVERLAY_NAME];
            annotationLayers.Add((InMemoryFeatureLayer)emphasisOverlay.Layers[HIGHLIGHT_LAYER_NAME]);
            annotationLayers.Add((InMemoryFeatureLayer)emphasisOverlay.Layers[REDLINE_LAYER_NAME]);
            annotationLayers.Add((InMemoryFeatureLayer)emphasisOverlay.Layers[ANNOTATION_LAYER_NAME]);

            redLineSerial.Serialize(annotationLayers, @"C:\ProgramData\Pear Technology\newMapper\redLineLayer.xml");

 


Am I doing something wrong or is serialization not intended to work that way?


Thanks,

Jonathan


 



Hi Jonathan, 
  
 The GeiSerializer could not serialize the generic types directly, you can make it as a field in a class and serialize the class. 
  
 Hope it helps, 
 Edgar

Thank you, I'll give that a try today.


Jonathan



That worked very easily.  I expect I will need to think through a bit more what I really need but for a quick starter this was perfect: 
 
    [Serializable]
    class clsAnnotationDetails
    {
        public GeoCollection<InMemoryFeatureLayer> mAnnotationLayers {get; set;}
    } 


Glad to hear that your problem has been solved, if you have any questions please let us know. 
  
 Regards, 
 Edgar

Bit of a gap - but Hi again Edgar and I do have a follow up question. When migrating from MapSuite10 to MapSuite13 is it possible for GeoSerializer to manage the change? I get the impression the namespace changes but not sure about the actual classes?

Regards,
Jonathan

Hi Jonathan,

The GeoSerializer object is the same in v13, but the objects it serializes may have changed. You may have to manually port some namespaces to get the xml to work in v13. I recommend you GeoSerialize something similar in v13 and compare to v10 to see the differences.

Let us know if you have any other questions.

Thanks,

Ben

Hi Ben,

Thanks, that is useful. One change we noticed with the printer image layer is that had changed to . But apart from that it was just the namespace.

When you say manually port the namespaces, how would we do that?

Regards,
Jonathan

Hi Jonathan,

Take note of the changes in the v13 GeoSerializer output compared to v10, then make those namespace changes in your v10.

Below is a screenshot and a link of the v10 to v12 guide using the search and replace function.

https://thinkgeo.com/blog/thinkgeo-10-to-12-conversion-guide

Alternatively, you can write a program to go through your stored XML serialized objects that changes the namespaces.

Let us know if this works.

Thanks,

Ben

Hi Ben,
Something along those lines did work OK. Although we embedded the namespace / other XML differences checking in the application and modify as required, allowing translation both ways.

Jonathan

Hi Jonathan,

Glad to hear everything is working!

Thanks,
John