none
Trying to set DataContext in MapControl on OS build 17134 causes a crash. RRS feed

  • Question

  • Trying to set DataContext for MapControl on OS build 17134 causes the app to crash but the same code works fine on a machine running the OS 16299.

    When setting "DataContext=this" for MapControl before providing the MapServiceToken value, I am getting the exception:

    Message: External component has thrown an exception.

    Source: Windows

    StackTrace: 

      at Windows.UI.Xaml.FrameworkElement.put_DataContext(Object value)
       at App1.MainPage..ctor()
       at App1.App1_XamlTypeInfo.XamlTypeInfoProvider.Activate_0_MainPage()
       at App1.App1_XamlTypeInfo.XamlUserType.ActivateInstance()

    But the application is working fine if I am setting "DataContext=this" after providing the MapServiceToken value.

    This issue is reproduced in OS build 17134.

    The same code is working fine in OS build 16299.

    This is my application code:

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Runtime.InteropServices.WindowsRuntime;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Navigation;
    
    namespace App1
    {
        public sealed partial class MainPage : Page
        {
            public string ServiceToken
            {
                get { return (string)GetValue(ServiceTokenProperty); }
                set { SetValue(ServiceTokenProperty, value); }
            }
    
            public static readonly DependencyProperty ServiceTokenProperty = DependencyProperty.Register(
                "ServiceToken",
                typeof(string),
                typeof(MainPage),
                new PropertyMetadata(string.Empty));
    
            private string mapKey = "__BINGMAPSPROVIDEDKEY__";
            public MainPage()
            {
                this.InitializeComponent();
                DataContext = this;
                ServiceToken = mapKey;
            }
        }
    }
    

    This is the xaml code for the same page, "MainPage" :

    <Page
        x:Class="App1.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:App1"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
        xmlns:maps="using:Windows.UI.Xaml.Controls.Maps">
        <Grid>
            <maps:MapControl
                MapServiceToken="{Binding ServiceToken}"
                />
        </Grid>
    </Page>
    

    Why this issue came in picture with the OS update?


    Rohit Garg.

    Tuesday, September 18, 2018 11:56 AM

All replies

  • Are you using a Bing maps key that was created for use with Windows UWP applications? Keys created for use with the web control will not work.
    Tuesday, September 18, 2018 4:52 PM
    Moderator
  • NOTE: We have also seen issues with leading or trailing spaces.  Not a crash however, just denial of credential.
    Tuesday, September 18, 2018 11:32 PM
    Owner
  • I am using Bing maps key that was created for use with Windows UWP applications. I am not having an issue with setting the key.
    The issue is with setting the DataContext of the control and it was working till I updated my OS from 15299 to 17134. I have mentioned it in detail before. Could you please tell why am I facing this issue now?



    Rohit Garg.

    Wednesday, September 19, 2018 6:44 AM
  • Not sure about this issue, but that seems like an unnecessarily complex way of setting the service token. Most apps just set it directly in the XAML or code behind - there's really no reason to use data binding here as it's not a value that will change during runtime.
    Wednesday, September 19, 2018 5:06 PM
    Moderator