ThinkGeo.com    |     Blog    |     Wiki    |     Support

Collection was modified; enumeration operation may not execute on Tile.Draw

I am not doing anything in particular to trigger this exception yet the map will occasionally crash my desktop application. How do I guard the application against such a crash?

I am running ThinkGeo v10 on Windows 10.

System.Transactions Critical: 0 : http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/UnhandledUnhandled exceptionDoseWin.exeSystem.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089Collection was modified; enumeration operation may not execute. at ThinkGeo.MapSuite.Wpf.Tile.DrawException(GeoCanvas geoCanvas, Exception exception)
at ThinkGeo.MapSuite.Wpf.Tile.Draw(GeoCanvas geoCanvas)
at ThinkGeo.MapSuite.Wpf.Tile.vVk=(Object status)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at ThinkGeo.MapSuite.Wpf.Tile.DrawException(GeoCanvas geoCanvas, Exception exception)
at ThinkGeo.MapSuite.Wpf.Tile.Draw(GeoCanvas geoCanvas)
at ThinkGeo.MapSuite.Wpf.Tile.vVk=(Object status)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
An unhandled exception of type ‘System.InvalidOperationException’ occurred in ThinkGeo.MapSuite.Wpf.dll
Collection was modified; enumeration operation may not execute.

Hi Klaus,

We met this type exception before, but most scenarios we had solved it.

Could you please upload a simple sample to reproduce it, so our developer can look into it.

Regards,

Ethan

Ethan,

I cannot provide a sample which could reliably duplicate this problem. There is something in the Draw method causing this. Are you guys drawing on an IEnumerable perhaps?

This issue occurs randomly and is causing excitement in the field.

I am also occasionally getting this too:

‘DoseWin.exe’ (CLR v4.0.30319: DoseWin.exe): Loaded ‘C:\dev\dosewin\App\Dosewin\bin\Debug\ThinkGeo.MapSuite.Styles.Value.dll’.
Exception thrown: ‘System.InvalidOperationException’ in ThinkGeo.MapSuite.dll
Exception thrown: ‘System.InvalidOperationException’ in ThinkGeo.MapSuite.Wpf.dll
An unhandled exception of type ‘System.InvalidOperationException’ occurred in ThinkGeo.MapSuite.Wpf.dll
The FeatureSource is not open. Please call the Open method before calling this method.

Hi Klaus,

We have some collections to save overlays, layers, tiles and features, they are related with drawing. So we need more information to locate where is the problem.

If you don’t have a sample to reproduce it, could you please let us know more information for example: your detail version, which layers you are using, what’s the operation before exception is thrown, whether you have some custom code or custom class to be used etc. So we can try to research it and see what we can find.

From the exception, it looks that’s a multiply threading issue, but generally this type exception is hard to met because we did many work to solve it before. So your scenario should be helpful.

And I think you should want to upgrade your map to latest version. In fact our Version 12 support .net framework also, you can try it because the underlying structure is not the same.

For the layer open problem, you can try to find all your layers, open it when it get initialized, and don’t close it before it removed from map or map close. The exception shows value style try to draw the feature in one layer, but we don’t know which layer is drawing. You should want to comment your layers and uncomment them one by one to make sure which layer cause it, we want to know how the layer is used so we can help you to solve it.

Regards,

Ethan

Ethan,

Thanks for the response. Should I be able to get v12 off Nuget?

Hi Klaus,

Yes, you can also get our version 12 from Nuget:

Please remove version 10 packages before use version 12 package.

Regards,

Ethan

Ethan,

Thanks for the response. I do not think this is an option for this application which is based on the regular .NET framework. I just tried the update the project and received this error:

Severity Code Description Project File Line Suppression State
Error Could not install package ‘ThinkGeo.Dependency.NetTopologySuite 12.2.1’. You are trying to install this package into a project that targets ‘.NETFramework,Version=v4.5.2’, but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

This exception is happening if I already have a shapefile layer on the map and I try to add a feature layer. The exception is:

2020-03-18 20:30:36,195 [6] DEBUG Infrastructure.Dictionary.Facades.Log4NetFacade [(null)] - Feature layer created with context MapId:Infrastructure.Dictionary.UniqueNameAlias,Action:0,ResourceType:GeoDataset,DataManager:Infrastructure.Dictionary.Data.DynamicGeoDataManager`1[Dosewin.Core.Models.DoseRegion]
2020-03-18 20:30:36,246 [6] DEBUG Infrastructure.Dictionary.Facades.Log4NetFacade [(null)] - Attempting to refresh map with this new layer.
2020-03-18 20:30:36,349 [9] ERROR Isr.Dosewin.Desktop.UBootstrapper [(null)] - System.InvalidOperationException: The FeatureSource is not open. Please call the Open method before calling this method.
at ThinkGeo.MapSuite.Wpf.Tile.DrawException(GeoCanvas geoCanvas, Exception exception)
at ThinkGeo.MapSuite.Wpf.Tile.Draw(GeoCanvas geoCanvas)
at ThinkGeo.MapSuite.Wpf.Tile.tVk=(Object status)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

Really need to resolve this issue as it is causing my client excitement.

Hi Klaus,

That’s because for version 12, it require the .net framework version is higher than 4.6.1.

It looks your project is 4.5.2.

Here is a sample works for .net framework 4.6.1, you can modify it and test it whether have the same problem.

9674.zip (1.1 MB)

Any question please let us know.

Regards,

Ethan

Ethan,

Thanks for the response.

Upgrading to v12 is not an option for a March delivery. Can you please advise on steps I should take to mitigate this crash. This application is used in a critical industry.

Either the application is crashing with the above message or with the message indicating “Feature source is not open…”

Klaus

Thanks for the response Ethan.

You are correct in that this maybe a multi-threading issue. I have been able to narrow this down.

Think I am doing too much to react to Features being created on a layer so that I can trigger an overlay after refresh.

I have created an event called FeaturesCreated on a FeatureLayer. This event is fired after features in the layer are recreated and I use this event to trigger an overlay refresh. Looks like I am firing too many of these events and not giving the Overlay a chance to complete…

However, I am also occasionally getting this:

An unhandled exception of type ‘System.InvalidOperationException’ occurred in ThinkGeo.MapSuite.Wpf.dll
The Layer must be opened before you can perform this method.

Not sure if this is all related but certainly causing some anxiety.

How do you guys handle this?

Klaus1,
I think this is something about the calling sequence.

  1. You may need call .Open before you do any others layer operation.
  2. Do not close the layer before the operation done. or even do not close the layer after open it.
  3. I found there are few threading talking about the same error your met. such as Display the full size of the shapefile
    You can search “The Layer must be opened before you can perform this method” in the discussion form see if one of them match your case.
  4. If still not work. we may need a simple sample to isolate the issue and then we can look into the detail.

I am still trying to re-reproduce this one. Any code snippet or screen shot could be very helpful for me to re-produce this issue.

Thanks

Frank