Search code examples
c#uwptelerik

Telerik for UWP: Windows.UI.Xaml.UnhandledException


I'm following a tutorial on how to use telerik in a uwp app. This is the link to tutorial. I have followed the steps in the tutorial and i'm getting an error which seems not to be clear.

This is part of the information i'm getting from visual studio.

System.ArgumentException: Cannot create dynamic property getter for non-public types.
   at Telerik.Core.DynamicHelper.CreatePropertyValueGetter(Type type, String propertyName)
   at Telerik.UI.Xaml.Controls.Chart.PropertyNameDataPointBinding.GetValue(Object instance)
   at Telerik.UI.Xaml.Controls.Chart.CategoricalSeriesDataSource.InitializeBinding(DataPointBindingEntry binding)
   at Telerik.UI.Xaml.Controls.Chart.ChartSeriesDataSource.GenerateDataPoint(Object dataItem, Int32 index)
   at Telerik.UI.Xaml.Controls.Chart.ChartSeriesDataSource.BindCore()
   at Telerik.UI.Xaml.Controls.Chart.ChartSeriesDataSource.Bind()
   at Telerik.UI.Xaml.Controls.Chart.ChartSeriesDataSource.Rebind(Boolean itemsSourceChanged, IEnumerable newSource)
   at Telerik.UI.Xaml.Controls.Chart.ChartSeries.OnTemplateApplied()
   at Telerik.UI.Xaml.Controls.RadControl.OnApplyTemplate()
   at Windows.UI.Xaml.FrameworkElement.MeasureOverride(Size availableSize)
   at Telerik.UI.Xaml.Controls.RadControl.MeasureOverride(Size availableSize)

as well as this

Windows.UI.Xaml.UnhandledExceptionEventArgs

MainPage.xaml.cs contains this code:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using TryOutTelerikUI.Models;
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;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace TryOutTelerikUI
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            this.DataContext = CityManager.GetCities();
        }
    }
}

and the MainPage.xaml file:

<Page
    x:Class="TryOutTelerikUI.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TryOutTelerikUI"
    xmlns:models="using:TryOutTelerikUI.Models"
    xmlns:telerik="using:Telerik.UI.Xaml.Controls.Chart"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <telerik:RadCartesianChart Name="RadChart">
            <telerik:RadCartesianChart.HorizontalAxis>
                <telerik:CategoricalAxis />
            </telerik:RadCartesianChart.HorizontalAxis>
            <telerik:RadCartesianChart.VerticalAxis>
                <telerik:LinearAxis />
            </telerik:RadCartesianChart.VerticalAxis>
            <telerik:LineSeries ItemsSource="{Binding}">
                <telerik:LineSeries.ValueBinding>
                    <telerik:PropertyNameDataPointBinding PropertyName="Value"/>
                </telerik:LineSeries.ValueBinding>
                <telerik:LineSeries.CategoryBinding>
                    <telerik:PropertyNameDataPointBinding PropertyName="Name"/>
                </telerik:LineSeries.CategoryBinding>
            </telerik:LineSeries>
        </telerik:RadCartesianChart>
    </Grid>
</Page>

The other classes used in the app are: The city class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TryOutTelerikUI.Models
{
    class City
    {
        public string Name { get; set; }
        public double Value { get; set; }
    }
}

and the citymanager class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TryOutTelerikUI.Models
{
    class CityManager
    {
        private static Random Random = new Random();
        private static string[] CityNames = new string[] { "Melbourne", "Sydney", "Brisbane", "Adelaide", "Perth" };

        public static List<City> GetCities()
        {
            List<City> cities = new List<City>();

            foreach(var cityName in CityNames) cities.Add(new City() { Name = cityName, Value = Random.Next(50, 100) });

            return cities;
        }
    }
}

The error comes from App.g.i.cs from the line of code inside the if statement.

#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
            UnhandledException += (sender, e) =>
            {
                if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
            };
#endif

Solution

  • The error gives some clues what might be the reason:

    Cannot create dynamic property getter for non-public types.
    

    You can see that you haven't see public access modifier for City and CityManager classes. Change those and try again. Further information for the error can be found in the available source code.