I'm trying to load some basemap tiles (as individual LocalTiledLayer) based on the current map extent and whist doing that also trying to remove tiles (LocalTiledLayer) which were previously loaded but not in the current map extent.
An unhandled exception as shown in Capture1.png is thrown at the MapView.Map.Layers.Remove line. Further digging in Visual Studio watch, looks like the layer itself is not null but none of its properties are accessible (as shown in Capture2.png) which could be the reason for this exception. I could be completely wrong though. This behaviour is quite random as well and can't be reproduced consistently.
Any one had this experience? Any input is much appreciated.
Thanks for taking time to look into this.
Please find the attached txt file with the code snippets where I add and remove the tiles.
Few other observations:
Adding a try/catch block doesn't help to catch the exception. I have even tried to add a check to see if I can get the layer ID property correctly and only then proceed to remove the tile but that hasn't helped either. So, it looked like a timing issue and therefore I went in and added delays/checked for one layer to be completely unloaded and then proceeded with removing the next one. But, none of these has helped. Strangely, in debug mode if I place a breakpoint on the remove line, it doesn't fail at all. However, when running without debugging, it throws the unhandled exception.When deployed on to a device on release mode, the app crashes.
Please let me know if you want me to try any other workflow.
I think I hit the same issue while testing a different scenario. Getting error "invalid parameter was passed to a function that considers invalid parameters fatal." and if this is the same issue, that's not layer type specific.
Yes, the error message is exactly the same as you mentioned. Not sure what should cause this but I might get rid of this issue by adding a group layer and just altering (adding/removing layers to the group layer) the layer collection of the group layer, rather than directly using the remove method on a map layer. I'm yet to confirm this by testing on a device although this works without issues on a visual studio simulator.