Intermittent exception Cannot create instance of type 'Bing.Maps.Map'

Answered Intermittent exception Cannot create instance of type 'Bing.Maps.Map'

  • Sunday, July 22, 2012 12:28 AM
     
     

    Sometimes my app produces this exception:

    An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in Grid1.exe but was not handled in user code

    WinRT information: Cannot create instance of type 'Bing.Maps.Map' [Line: 81 Position: 44]

    Additional information: Unspecified error

    If there is a handler for this exception, the program may be safely continued.

    --------------------

    In the debugger, examining the exception variable shows text like this:

    Exception = {"Error HRESULT E_FAIL has been returned from a call to a COM component."}
    Message = "Cannot create instance of type 'Bing.Maps.Map' [Line: 71 Position: 13]"

    ------------------

    Sometimes the debugger stops at the InitializeComponent call. Sometimes it stops in a ".g" generated source file.

    In this app, the opening "Group" page is a GridView with a map control. The user can navigate to an "Item Details" page consisting of a FlipView. The FlipView also contains a Bing map. The exception is intermittently thrown when the Back button is used to navigate back from the FlipView to the GridView page.  I can manipulate the maps in the GridView page and FlipView page without any apparent problems. It is only when navigating back to the first page that the exception sometimes (not always) occurs.

    So, does this sound like a bug in my app, in the Bing Maps control, or what? Can anyone suggest a work-around?

    Thanks,

    Rick

All Replies

  • Tuesday, July 24, 2012 3:24 PM
     
     Answered

    You may get an exception creating the Map if we are unable to allocate a graphics device since without it we can't render anything making the map object useless. The recommended solution is to Dispose the map as soon as you are done with it. Unfortunately there is a compiler bug on the RP release which prevents Dispose from working properly and you get a spectacular access violation instead.

    If you want to work around it on the Release Preview create one map up front and reuse it between the different pages.

    • Marked As Answer by Bucolic Geek Tuesday, July 24, 2012 3:29 PM
    •  
  • Sunday, November 04, 2012 10:20 PM
     
     

    So how do you make one map up front. What exactly do you mean by that.

  • Monday, November 05, 2012 4:59 PM
     
     
    This is now obsolete; the graphics device is shared between all instances of a Map. You may still get an exception creating a Map if no graphics device can be created but as long as you can create one (and hold on to it) no other Map instances should fail to be created.
  • Monday, November 05, 2012 5:31 PM
     
     

    I have Windows 8 RP on my laptop. And Visual studio 12 express.

    I tried one of the map samples and still getting the same error which is:

    An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in test.ext but was not handled in user code

    WinRT information: Cannot create instance of type 'Bing.Maps.Map' [Line: 56 Position: 26]

    And also in the MainPage.xaml file i get this msg (The procedure could not be found. HResult: some number) when i hover over the place where I am using my bing map key.

  • Monday, November 05, 2012 5:44 PM
     
     

    I recommend you upgrade to RTM.

  • Monday, November 05, 2012 7:28 PM
     
     
    Thanks Kristoffer for prompt replies. That is what I am going to do.