Map component crashes when switching modes using Bing Provider

3 posts, 0 answers
  1. Hafsa
    Hafsa avatar
    8 posts
    Member since:
    Mar 2013

    Posted 04 May 2015 Link to this post


    I have a custom WPF control that contains the RadMap in its control template. The provider is Bing and the mode is set to "Road" mode. When switching the map to Aerial mode, the application crashes and I see the following error:

    InvalidOperationException was unhandled: Cannot set a property on object 'Telerik.Windows.Controls.Map.BingMapProvider' because it is in a read-only state.

     This does not happen with the ArcGIS or OSM provider. I would really like to use the Bing provider though... any idea what might be causing this?

  2. Martin
    Martin avatar
    1101 posts

    Posted 07 May 2015 Link to this post

    Hello Hafsa,

    The reported behavior is caused by the fact that the BingMapProvider derives from the Freezable class. When you define a freezable object in a DataTemplate, ControlTemplate or any resource, the WPF framework automatically freezes it and it cannot be further modified. This is why when you define RadMap into the ControlTemplate of the custom control the exception is thrown when the provider's Mode property is changed.

    The OpenStreeMap and ArcGIS providers are also freezable object, but their mechanism of changing the view mode is different and this exception doesn't occur. 

    In order to resolve this for the BingMapProvider you can create a custom provider that derives from the bing map and override its FreezeCore() method, then cancel the freezing. Here is an example:
    public class MyBingProvider : BingMapProvider
        protected override bool FreezeCore(bool isChecking)
            return false;

            <local:MyBingProvider />
    Please try this approach and let me know if it works for you.


    See What's Next in App Development. Register for TelerikNEXT.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Hafsa
    Hafsa avatar
    8 posts
    Member since:
    Mar 2013

    Posted 07 May 2015 Link to this post

    This works great. Thank you!
Back to Top