We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Error: XLS0503: A value of type 'ArrayExtension' cannot be added to a collection or dictionary of type 'Double[]'.

Hi,

I'm getting this error when compiling for Release mode on Android

Error: XLS0503: A value of type 'ArrayExtension' cannot be added to a collection or dictionary of type 'Double[]'. 

However the app runs fine and the chart renders okay in debug mode.

This code was originally based on the SyncFusion sample code and documentation, so I'm confident it should be valid syntax and working.

Specifically it affects this block from the line containing '<x:Array Type="{x:Type x:Double}">'

I am using Syncfusion.Xamarin.SfChart 20.2.0.36 and Xamarin Forms 5.0.0.2478, Visual Studio for Mac 17.4 (build 2406)

<chart:SfChart.Series>
  <chart:ColumnSeries ItemsSource="{Binding Aggregation}" Label="Average" Color="Silver" XBindingPath="Period" YBindingPath="Avg" EnableTooltip="True">
    <chart:ColumnSeries.Trendlines>
        <chart:ChartTrendlineCollection>
            <chart:ChartTrendline ForwardForecast="3" Label="Trend + Prediction">
                <chart:ChartTrendline.StrokeDashArray>
                    <x:Array Type="{x:Type x:Double}">
                        <sys:Double>5</sys:Double>
                        <sys:Double>6</sys:Double>
                    </x:Array>
                </chart:ChartTrendline.StrokeDashArray>
            </chart:ChartTrendline>
        </chart:ChartTrendlineCollection>
    </chart:ColumnSeries.Trendlines>
  </chart:ColumnSeries>
</chart:SfChart.Series>
</chart:SfChart>

Here's the full code for the page

<?xml version="1.0" encoding="utf-8"?>

<ContentPage xmlns:fontawesome="clr-namespace:FontAwesome"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:chart="clr-namespace:Syncfusion.SfChart.XForms;assembly=Syncfusion.SfChart.XForms"
             x:Class="MyApp.Views.ReportPage"
             xmlns:sys="clr-namespace:System;assembly=netstandard"
             Title="Answers"
             BackgroundColor="{DynamicResource PageBackgroundColor}"
             IconImageSource="icon859barcharttoolbar.png"
             xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
             ios:Page.UseSafeArea="true"
             Padding="6,6,6,6">


    <ContentPage.Resources>


    </ContentPage.Resources>


    <ScrollView VerticalOptions="FillAndExpand">


        <StackLayout Orientation="Vertical">


            <Grid ColumnDefinitions="*,*,*" RowDefinitions="*">
                <Label Grid.Column="0" Grid.Row="0" Text="Aggregation:" VerticalTextAlignment="Center"/>
                <Label Grid.Column="1" Grid.Row="0" Text="{Binding PeriodAggregation}" VerticalTextAlignment="Center"/>
                <Button Grid.Column="2" Grid.Row="0" Text="Change" Command="{Binding PeriodAggregationCommand}"/>
            </Grid>


            <StackLayout BindableLayout.ItemsSource="{Binding ChartResultResponse.ChartResults}">


             <BindableLayout.ItemTemplate>
                    <DataTemplate>


                        <StackLayout Orientation="Vertical">


                             <chart:SfChart BindingContext="{Binding .}" SideBySideSeriesPlacement="false" HorizontalOptions="FillAndExpand" HeightRequest="400">


                                <chart:SfChart.Legend>
                                  <chart:ChartLegend />
                                </chart:SfChart.Legend>


                                <chart:SfChart.Title>
                                  <chart:ChartTitle Text="{Binding Question.Title}"/>
                                </chart:SfChart.Title>


                                <chart:SfChart.PrimaryAxis>
                                  <chart:CategoryAxis>
                                    <chart:CategoryAxis.Title>
                                      <chart:ChartAxisTitle Text="Period"/>
                                    </chart:CategoryAxis.Title>
                                  </chart:CategoryAxis>
                                </chart:SfChart.PrimaryAxis>


                                <chart:SfChart.SecondaryAxis>
                                  <chart:NumericalAxis>
                                    <chart:NumericalAxis.Title>
                                      <chart:ChartAxisTitle Text="Users Answer"/>
                                    </chart:NumericalAxis.Title>
                                  </chart:NumericalAxis>
                                </chart:SfChart.SecondaryAxis>


                                <chart:SfChart.Series>
                                  <chart:ColumnSeries ItemsSource="{Binding Aggregation}" Label="Average" Color="Silver" XBindingPath="Period" YBindingPath="Avg" EnableTooltip="True">
                                    <chart:ColumnSeries.Trendlines>
                                        <chart:ChartTrendlineCollection>
                                            <chart:ChartTrendline ForwardForecast="3" Label="Trend + Prediction">
                                                <chart:ChartTrendline.StrokeDashArray>
                                                    <x:Array Type="{x:Type x:Double}">
                                                        <sys:Double>5</sys:Double>
                                                        <sys:Double>6</sys:Double>
                                                    </x:Array>
                                                </chart:ChartTrendline.StrokeDashArray>
                                            </chart:ChartTrendline>
                                        </chart:ChartTrendlineCollection>
                                    </chart:ColumnSeries.Trendlines>
                                  </chart:ColumnSeries>
                                </chart:SfChart.Series>
                              </chart:SfChart>
                        </StackLayout>
                    </DataTemplate>
                </BindableLayout.ItemTemplate>
            </StackLayout>
        </StackLayout>
    </ScrollView>
</ContentPage>

Unfortunately the screenshot is over 100KB so I can't show the error (this 100KB limit seems a little low)


3 Replies 1 reply marked as answer

RR Raja Ramalingam Syncfusion Team December 5, 2022 02:05 PM UTC

Hi Rob Wilson,

We would like to tell you that the error you are facing is at the XAML syntax level only. It is due to the mismatching type between the StrokeDashArray property and the array we are giving. Using this syntax in our end, the chart is working fine with trend lines in both release mode and debug mode.

If you like to avoid this syntax error means, we would like to suggest you the alter ways of achieving this requirement.

1.We can achieve the dashed trend lines by setting the array collection to StrokeDashArray property in the code behind as per the following code example.

<chart:ColumnSeries>

    <chart:ColumnSeries.Trendlines>

        <chart:ChartTrendlineCollection>

            <chart:ChartTrendline x:Name="trendLine" ForwardForecast="3"

                                  Label="Trend + Prediction">

            </chart:ChartTrendline>

        </chart:ChartTrendlineCollection>

    </chart:ColumnSeries.Trendlines>

</chart:ColumnSeries>


public partial class MainPage : ContentPage

{

    public MainPage()

    {

        InitializeComponent();

 

        trendLine.StrokeDashArray = new double[] { 5, 4 };

    }

}


2.Also we can achieve the dashed trend lines by adding an array collection in the chart resources and set it to the StrokeDashArray property as per the following code example.

<chart:SfChart.Resources>

    <ResourceDictionary>              

        <x:Array x:Key="trendLineArray" Type="{x:Type x:Double}">

            <x:Double>5</x:Double>

            <x:Double>4</x:Double>

        </x:Array>           

    </ResourceDictionary>

</chart:SfChart.Resources>


<chart:ColumnSeries>

    <chart:ColumnSeries.Trendlines>

        <chart:ChartTrendlineCollection>

            <chart:ChartTrendline ForwardForecast="3" Label="Trend + Prediction"

             StrokeDashArray="{StaticResource Key=trendLineArray}">

            </chart:ChartTrendline>

        </chart:ChartTrendlineCollection>

    </chart:ColumnSeries.Trendlines>

</chart:ColumnSeries>


And please let us know if you need any further assistance.


Regards,

Raja.


Marked as answer

RW Rob Wilson December 22, 2022 01:12 PM UTC

Sorry for the delay in replying (Covid) ... I can confirm that using the Resource Dictionary workaround worked perfectly for me in debug and release modes.


Thank you.



PR Preethi Rajakandham Syncfusion Team December 23, 2022 06:49 AM UTC

Hi Rob,

We are glad that the provided response meets your requirement. Please let us know if you need further assistance. As always, we are happy to help you out.

Regards,

Preethi R


Loader.
Live Chat Icon For mobile
Up arrow icon