mauibar-chartsyncfusionsyncfusion-chart

.Net Maui App bar graph throwing XLS0414 error unexpectedly


I am working on a Maui App and want to add a graph, so I installed the Syncfusion.Maui.Charts NuGet Package. The issue is, in the code-behind I am getting the below error in my Frame where I have defined the graph;

Severity    Code    Description Project File    Line    Suppression State
Error (active)  XFC0000 Cannot resolve type "clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts:sfChart:BarSeries".   MauiApp1 (net8.0-android), MauiApp1 (net8.0-ios), MauiApp1 (net8.0-maccatalyst), MauiApp1 (net8.0-windows10.0.19041.0)  C:\Users\44751\source\repos\MauiApp1\MainPage.xaml  24  
Error   XLS0414 The type 'sfChart:BarSeries' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.   MauiApp1    C:\Users\44751\source\repos\MauiApp1\MainPage.xaml  24  

I can confirm that the Package does indeed appear under Dependencies in Solution Explorer and have tried uninstalling/reinstalling and deleting the bin and object folders and changing the namespace but nothing seems to work despite everything looking fine. I decided to do the basics and create a new, simple Project and installed the Syncfusion.Maui.Charts package, but same issue occurs despite how simple I have kept it. Below is the MainPage.xaml.cs;

using Syncfusion.Maui.Charts;
using Syncfusion.Maui.Core.Hosting;


namespace MauiApp1
{
    public partial class MainPage : ContentPage
    {
        public ObservableCollection<SalesData> SalesDataCollection { get; set; }

        public MainPage()
        {
            InitializeComponent();
            SalesDataCollection = new ObservableCollection<SalesData>
                {
                    new SalesData("Product A", 120),
                    new SalesData("Product B", 180),
                    new SalesData("Product C", 90),
                };

            BindingContext = this; // ✅ Set BindingContext
        }


    }

}

Below is the MainPage.xaml;

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:sfChart="clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts"
             x:Class="MauiApp1.MainPage">

    <VerticalStackLayout Padding="20">

        <Label Text="Syncfusion Chart Test" 
               FontSize="24" 
               HorizontalOptions="Center" 
               VerticalOptions="Start" />

        <sfChart:SfCartesianChart HorizontalOptions="FillAndExpand"
                                  VerticalOptions="FillAndExpand">
            <sfChart:SfCartesianChart.XAxes>
                <sfChart:CategoryAxis Title="Products"/>
            </sfChart:SfCartesianChart.XAxes>

            <sfChart:SfCartesianChart.YAxes>
                <sfChart:NumericalAxis Title="Sales"/>
            </sfChart:SfCartesianChart.YAxes>

            <sfChart:SfCartesianChart.Series>
                <sfChart:BarSeries ItemsSource="{Binding SalesDataCollection}"
                                   XBindingPath="ProductName"
                                   YBindingPath="SalesAmount"
                                   ShowDataLabels="True"/>
            </sfChart:SfCartesianChart.Series>

        </sfChart:SfCartesianChart>
    </VerticalStackLayout>

</ContentPage>

The error occurs at line 24 of the .xaml i.e. "<sfChart:BarSeries ItemsSource="{Binding SalesDataCollection}"" on the 'sfChart:BarSeries' part.

The MauiProgram.cs file looks like this;

using Microsoft.Extensions.Logging;
using Syncfusion.Maui.Core.Hosting;

namespace MauiApp1
{
    public static class MauiProgram
    {
        public static MauiApp CreateMauiApp()
        {
            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
                .ConfigureSyncfusionCore()  // ✅ Ensure this line is added
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                    fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
                });
            //builder.ConfigureSyncfusionCore(); // ✅ Register Syncfusion

#if DEBUG
            builder.Logging.AddDebug();
#endif

            return builder.Build();
        }
    }
}

For reference, the MauiApp1.csproj file looks like this;

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst;</TargetFrameworks>
        <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
        <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
        <!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->

        <!-- Note for MacCatalyst:
        The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
        When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
        The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
        either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
        <!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

        <OutputType>Exe</OutputType>
        <RootNamespace>MauiApp1</RootNamespace>
        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>

        <!-- Display name -->
        <ApplicationTitle>MauiApp1</ApplicationTitle>

        <!-- App Identifier -->
        <ApplicationId>com.companyname.mauiapp1</ApplicationId>

        <!-- Versions -->
        <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
        <ApplicationVersion>1</ApplicationVersion>

        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
        <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
    </PropertyGroup>

    <ItemGroup>
        <!-- App Icon -->
        <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

        <!-- Splash Screen -->
        <MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

        <!-- Images -->
        <MauiImage Include="Resources\Images\*" />
        <MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />

        <!-- Custom Fonts -->
        <MauiFont Include="Resources\Fonts\*" />

        <!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
        <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
        <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
        <PackageReference Include="Syncfusion.Maui.Charts" Version="28.2.7" />
    </ItemGroup>



</Project>

I am completely stumped as to why I am getting this error. I have attached a screenshot of the Dependencies in Solution Explorer and can confirm that the package name appears under the Packages node of each .net8.0; DependenciesScreenshot


Solution

  • The error occurs at line 24 of the .xaml i.e. "<sfChart:BarSeries ItemsSource="{Binding SalesDataCollection}"" on the 'sfChart:BarSeries' part.

    This is because there is no BarSeries class in the Syncfusion.Maui.Charts. If you want to use BarChart, you can check the official sample about the BarChart.

    <chart:SfCartesianChart IsTransposed="True">
    
        <chart:SfCartesianChart.XAxes>
            <chart:CategoryAxis/>
        </chart:SfCartesianChart.XAxes>
    
        <chart:SfCartesianChart.YAxes>
            <chart:NumericalAxis/>
        </chart:SfCartesianChart.YAxes>   
    
        <chart:ColumnSeries ItemsSource="{Binding Data}"
                            XBindingPath="XValue"
                            YBindingPath="YValue"/>
    
    </chart:SfCartesianChart>
    

    In addition, you can check all the Chart Types in the official doc.