ThinkGeo.com    |     Documentation    |     Premium Support

System.InvalidOperation Execption

Hi,
Mapsuite10 - Winforms, Getting this exception after some time of execution. Couldn’t find any particular reason or way to suppress. I’ve a small map with Inmemoryfeaturelayer autorefreshing @500ms. Zoomlevel 21/ 22 (Googlemaps equivalent).

Any suggestions/ pointers?

Stacktrace -
System.InvalidOperationException occurred
HResult=0x80131509
Message=The Layer must be opened before you can perform this method.
Source=ThinkGeo.MapSuite
StackTrace:
at ThinkGeo.MapSuite.ValidatorHelper.CheckLayerIsOpened(Boolean isOpen)
at ThinkGeo.MapSuite.Layers.FeatureLayer.DrawCore(GeoCanvas canvas, Collection1 labelsInAllLayers) at ThinkGeo.MapSuite.Layers.Layer.ZyU=(GeoCanvas canvas, Collection1 labelsInAllLayers)
at ThinkGeo.MapSuite.Layers.Layer.Draw(GeoCanvas canvas, Collection1 labelsInAllLayers) at ThinkGeo.MapSuite.WinForms.LayerOverlay.DrawCore(GeoCanvas canvas) at ThinkGeo.MapSuite.WinForms.Overlay.EFM=(GeoCanvas canvas) at ThinkGeo.MapSuite.WinForms.Overlay.Draw(GeoCanvas canvas) at ThinkGeo.MapSuite.WinForms.WinformsMap.xVI=(IEnumerable1 drawingOverlays, RectangleShape extent)
at ThinkGeo.MapSuite.WinForms.WinformsMap.xFI=(RectangleShape drawingExtent, RectangleShape extent)
at ThinkGeo.MapSuite.WinForms.WinformsMap.41I=(RectangleShape extent)
at ThinkGeo.MapSuite.WinForms.WinformsMap.gRU=(Int32 delayInterval, RectangleShape extent)
at ThinkGeo.MapSuite.WinForms.WinformsMap.Refresh(RectangleShape extent, IEnumerable1 overlays) at ThinkGeo.MapSuite.WinForms.WinformsMap./RU=(IEnumerable1 extentsToRefresh, IEnumerable1 overlays) at ThinkGeo.MapSuite.WinForms.WinformsMap.Tho=.Vho=() at ThinkGeo.MapSuite.WinForms.WinformsMap.Tho=.VRo=(o1M= parameter, RequestDrawingBufferTimeType bufferTimeType) at ThinkGeo.MapSuite.WinForms.WinformsMap.u1I=(Object sender, RequestedDrawingOverlayEventArgs e) at ThinkGeo.MapSuite.WinForms.Overlay.OnRequestedDrawing(RequestedDrawingOverlayEventArgs eventArgs) at ThinkGeo.MapSuite.WinForms.Overlay.bCU=(IEnumerable1 extentsToRefresh, TimeSpan bufferTime, RequestDrawingBufferTimeType bufferTimeType)
at ThinkGeo.MapSuite.WinForms.Overlay.RequestDrawing()
at ThinkGeo.MapSuite.WinForms.Overlay.b__88_0(Object , EventArgs )
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.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(IntPtr 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 TestApp.Program.Main() in D:\ThinkGeo\TestApp\TestApp\Program.cs:line 19

Hi Avinash,

Based on your exception message. It seems that you are trying to use one layer before it opening. Some operations can be performed before one layer opened(like layer.GetBoundingBox()). I didn’t see your code, I am not sure what the operations you take. But you can try to use below code to open layer in your code as test.

layer.Open();

If there is still issue, please post your code, I will check that for you.

Thanks
Mark

I feel I’ve figured reason for this exception.
I’m editing a InMemoryFeatureLayer in a thread and doing open/ close appropriately in thread handler (only one place in code after Initialization). As Map display and Mapsuite Internals act asynchrounous to my thread. There is a chance of such exception due to such asynchronous operation. I’d like to know how to fix this.

Hi Avinash,

I think if you are using multiply thread, please just open the layer but not close it until entire application is closed or specified InMemoryFeatureLayer is removed from your map.

Regards,

Ethan

Thanks Ethan,
I thought opening and closing immediately is required. I’d try opening required layers once and close at application close.

Hi Avinash,

In fact for an InMemoryFeatureLayer you don’t need to close it, because maybe some other APIs which will require the layer is opened. Just like I mentioned, I think you can choose to close the layer when you don’t want to use it again, and open it after it’s added to your application.

Any question please let us know.

Regards,

Don