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

SfCarousel System.NullReferenceException when trying to render

Hi,

I was wondering if someone of you got a tip for me regarding the following problem:

I've a xaml view with the following content:

xmlversion="1.0"encoding="UTF-8"?>
<ContentView
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TPApp.gui.views.category.CategoryHomeListView"
xmlns:carousel="clr-namespace:Syncfusion.SfCarousel.XForms;assembly=Syncfusion.SfCarousel.XForms">

<GridRowSpacing="0"ColumnSpacing="0">
<Grid.RowDefinitions>
<RowDefinitionHeight="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinitionWidth="*"/>
</Grid.ColumnDefinitions>


<Grid.Resources>
<ResourceDictionary>
<DataTemplatex:Key="tpProductItemTemplate">

<GridRowSpacing="0"ColumnSpacing="0"VerticalOptions="Center"HorizontalOptions="Center">
<Grid.RowDefinitions>
<RowDefinitionHeight="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinitionWidth="*"/>
</Grid.ColumnDefinitions>

<ImageSource="{BindingsImageUrl}"VerticalOptions="Center"HorizontalOptions="Center"Grid.Row="0"
Grid.Column="0"/>

</Grid>

</DataTemplate>
</ResourceDictionary>
</Grid.Resources>

<carousel:SfCarouselx:Name="tpProductCarousel"HeightRequest="400"WidthRequest="400"Grid.Row="0"
Grid.Column="0"ItemTemplate="{StaticResourcetpProductItemTemplate}"/>
</Grid>
</ContentView>



I'm adding the content via the following code in the .cs file:


publicCategoryHomeListView()
{
InitializeComponent();

tpProductCarousel.SetBinding(Syncfusion.SfCarousel.XForms.SfCarousel.DataSourceProperty,"aProducts");

}


The whole project is compiling fine. But as soon as I'm starting the program, I get the following exception:

System.NullReferenceException: Object reference not set to an instance of an object
at Syncfusion.SfCarousel.XForms.iOS.SfCarouselMapping.Convert (Xamarin.Forms.View source, Xamarin.Forms.VisualElement valid) [0x0002f] in <7b928492986e4ddaabcc39b707c50172>:0
at Syncfusion.SfCarousel.XForms.iOS.SfCarouselMapping.ConvertFormsToNative (Xamarin.Forms.DataTemplate view, System.nint index, CoreGraphics.CGRect size, Syncfusion.SfCarousel.XForms.SfCarousel formsCarousel) [0x0002a] in <7b928492986e4ddaabcc39b707c50172>:0
at Syncfusion.SfCarousel.XForms.iOS.SfCarouselMapping.OnCarouselPropertiesChanged (System.String propertyName, Syncfusion.SfCarousel.XForms.SfCarousel formsCarousel, Syncfusion.SfCarousel.iOS.SFCarousel nativeCarousel) [0x00379] in <7b928492986e4ddaabcc39b707c50172>:0
at Syncfusion.SfCarousel.XForms.iOS.SfCarouselRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) [0x000a3] in <7b928492986e4ddaabcc39b707c50172>:0

......


Does anyone of you know, why it accesses an empty object? The carousel has been added in the xaml and should have been initialized by calling
InitializeComponent(); ?


Thank you very much for your help.


Alex



12 Replies

RK Rathana Kumar Sekar Syncfusion Team June 21, 2017 11:36 AM UTC

Hi Toppreise,

Thanks for your update.

We have checked the reported issue with provided code and found ViewModel binding has not been implemented in your code. We have modified your code and prepared sample based on that. Please find the sample from the below link.

Sample: http://www.syncfusion.com/downloads/support/forum/131094/ze/Carouseltest-1850335403 

Please let us know if you have any other query.

Regards,
Rathanakumar S. 



TO Toppreise June 23, 2017 12:10 PM UTC

Hi Rathanakumar,

Thanks for the example code you attached to your reply.. The ViewModel Binding is one level above. First I thought you're right and I forgot the Context Binding. But I'm doing this outside of CategoryHomeListView like


CategoryHomeListView oObj = new CategoryHomeListView();

oObj.BindingContext = oCatObj;


oCatObj has the member "aProducts" which I use later for binding the item source.

The programm still doesn't work. I'll try some other things. I case you've got another tipp, I'd be happy if you could post it here.

Thank you very much for yor help!

Alex



TO Toppreise June 23, 2017 01:01 PM UTC

Hi,ok.. I tried a little bit more and think the solution comes closer.I did now the following:The XAML: xml version="1.0" encoding="UTF-8"?>                                                        And the source code: using System; using System.Collections.Generic; using Xamarin.Forms; namespace xyz.gui.views.category {     public partial class CategoryHomeListView : ContentView     {         public CategoryHomeListView(webint.entity.category.CategoryHome oCategory)         {             InitializeComponent();             this.BindingContext = oCategory;             testlabel.SetBinding(Label.TextProperty, "sName");             /* Syncfusion.SfCarousel.XForms.SfCarouselItem carouselItem1 = new Syncfusion.SfCarousel.XForms.SfCarouselItem();             Image img = new Image();             img.Source = ImageSource.FromUri(new Uri("http://cerealkillerz.org/wp-content/uploads/2015/12/yvqylz3c0ywhkpt1g8of.jpgimage2.png"));             img.Aspect = Aspect.AspectFit;             img.VerticalOptions = LayoutOptions.Center;             img.HeightRequest = 400;             img.WidthRequest = 400;             carouselItem1.ItemContent = img;             tpProductCarousel.ItemsSource.Add(carouselItem1);             Syncfusion.SfCarousel.XForms.SfCarouselItem carouselItem = new Syncfusion.SfCarousel.XForms.SfCarouselItem();             Label lbl = new Label();             lbl.Text = "  Item No: 1 ";             lbl.BackgroundColor = Color.Gray;             lbl.FontSize = 25;             lbl.VerticalTextAlignment = TextAlignment.Center;             carouselItem.ItemContent = lbl;             tpProductCarousel.ItemsSource.Add(carouselItem);  */         }     } } And now the strange thing:If I dont add any of the items above to the SfCarousel (the part in the code which I commented) it works like charm. I see the list of my categories with the light blue SfCarousel. But as soon as I try to add the items as you see it above (e.g. as soon as I remove the /* and */), it crashes at runtime. The message is the following:Caught Exception 1: System.NullReferenceException: Object reference not set to an instance of an object  at Syncfusion.SfCarousel.XForms.iOS.SfCarouselRenderer.Convert (Xamarin.Forms.View source, Xamarin.Forms.VisualElement valid) [0x0002f] in <7b928492986e4ddaabcc39b707c50172>:0   at Syncfusion.SfCarousel.XForms.iOS.SfCarouselRenderer.ConvertFormsToNative (Xamarin.Forms.View view, CoreGraphics.CGRect size, Syncfusion.SfCarousel.XForms.SfCarousel formsCarousel) [0x00007] in <7b928492986e4ddaabcc39b707c50172>:0   at Syncfusion.SfCarousel.XForms.iOS.SfCarouselItemMapping.OnCarouselItemPropertiesChanged (System.String propertyName, Syncfusion.SfCarousel.XForms.SfCarouselItem formsItem, Syncfusion.SfCarousel.iOS.SFCarouselItem nativeItem) [0x0004a] in <7b928492986e4ddaabcc39b707c50172>:0   at Syncfusion.SfCarousel.XForms.iOS.SfCarouselItemMapping.GetNativeItem (Syncfusion.SfCarousel.XForms.SfCarouselItem item, Syncfusion.SfCarousel.XForms.SfCarousel carousel) [0x0002f] in <7b928492986e4ddaabcc39b707c50172>:0   at Syncfusion.SfCarousel.XForms.iOS.SfCarouselMapping.OnCarouselPropertiesChanged (System.String propertyName, Syncfusion.SfCarousel.XForms.SfCarousel formsCarousel, Syncfusion.SfCarousel.iOS.SFCarousel nativeCarousel) [0x0005b] in <7b928492986e4ddaabcc39b707c50172>:0   at Syncfusion.SfCarousel.XForms.iOS.SfCarouselRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) [0x000a3] in <7b928492986e4ddaabcc39b707c50172>:0 I'm pretty sure that the more complex styling problem will be solved as soon as I get this to work.Cloud you have another look to the source code? Thank you very much.Alex


TO Toppreise June 23, 2017 01:02 PM UTC

Hi,

ok.. I tried a little bit more and think the solution comes closer.

I did now the following:

The XAML:


<?xml version="1.0" encoding="UTF-8"?>
<ContentView 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    x:Class="xyz.gui.views.category.CategoryHomeListView"
    xmlns:carousel="clr-namespace:Syncfusion.SfCarousel.XForms;assembly=Syncfusion.SfCarousel.XForms" >


    <StackLayout>
        
        <carousel:SfCarousel x:Name="tpProductCarousel" HeightRequest="400" WidthRequest="400" BackgroundColor="Aqua" Margin="20" Grid.Row="0" 
                                                Grid.Column="0" />
        
        <Label x:Name="testlabel" />
        
    </StackLayout>


</ContentView>


And the source code:


using System;
using System.Collections.Generic;
using Xamarin.Forms;

namespace xyz.gui.views.category
{




    public partial class CategoryHomeListView : ContentView
    {
        public CategoryHomeListView(webint.entity.category.CategoryHome oCategory)
        {
            InitializeComponent();

            this.BindingContext = oCategory;

            testlabel.SetBinding(Label.TextProperty, "sName");

            /* Syncfusion.SfCarousel.XForms.SfCarouselItem carouselItem1 = new Syncfusion.SfCarousel.XForms.SfCarouselItem();
            Image img = new Image();
            img.Source = ImageSource.FromUri(new Uri("http://cerealkillerz.org/wp-content/uploads/2015/12/yvqylz3c0ywhkpt1g8of.jpgimage2.png"));
            img.Aspect = Aspect.AspectFit;
            img.VerticalOptions = LayoutOptions.Center;
            img.HeightRequest = 400;
            img.WidthRequest = 400;
            carouselItem1.ItemContent = img;
            tpProductCarousel.ItemsSource.Add(carouselItem1);

            Syncfusion.SfCarousel.XForms.SfCarouselItem carouselItem = new Syncfusion.SfCarousel.XForms.SfCarouselItem();
            Label lbl = new Label();
            lbl.Text = "  Item No: 1 ";
            lbl.BackgroundColor = Color.Gray;
            lbl.FontSize = 25;
            lbl.VerticalTextAlignment = TextAlignment.Center;
            carouselItem.ItemContent = lbl;
            tpProductCarousel.ItemsSource.Add(carouselItem);  */


        }
    }
}

And now the strange thing:

If I dont add any of the items above to the SfCarousel (the part in the code which I commented) it works like charm. I see the list of my categories with the light blue SfCarousel. But as soon as I try to add the items as you see it above (e.g. as soon as I remove the /* and */), it crashed at runtime. The message is the following:


Caught Exception 1: System.NullReferenceException: Object reference not set to an instance of an object
  at Syncfusion.SfCarousel.XForms.iOS.SfCarouselRenderer.Convert (Xamarin.Forms.View source, Xamarin.Forms.VisualElement valid) [0x0002f] in <7b928492986e4ddaabcc39b707c50172>:0
  at Syncfusion.SfCarousel.XForms.iOS.SfCarouselRenderer.ConvertFormsToNative (Xamarin.Forms.View view, CoreGraphics.CGRect size, Syncfusion.SfCarousel.XForms.SfCarousel formsCarousel) [0x00007] in <7b928492986e4ddaabcc39b707c50172>:0
  at Syncfusion.SfCarousel.XForms.iOS.SfCarouselItemMapping.OnCarouselItemPropertiesChanged (System.String propertyName, Syncfusion.SfCarousel.XForms.SfCarouselItem formsItem, Syncfusion.SfCarousel.iOS.SFCarouselItem nativeItem) [0x0004a] in <7b928492986e4ddaabcc39b707c50172>:0
  at Syncfusion.SfCarousel.XForms.iOS.SfCarouselItemMapping.GetNativeItem (Syncfusion.SfCarousel.XForms.SfCarouselItem item, Syncfusion.SfCarousel.XForms.SfCarousel carousel) [0x0002f] in <7b928492986e4ddaabcc39b707c50172>:0
  at Syncfusion.SfCarousel.XForms.iOS.SfCarouselMapping.OnCarouselPropertiesChanged (System.String propertyName, Syncfusion.SfCarousel.XForms.SfCarousel formsCarousel, Syncfusion.SfCarousel.iOS.SFCarousel nativeCarousel) [0x0005b] in <7b928492986e4ddaabcc39b707c50172>:0
  at Syncfusion.SfCarousel.XForms.iOS.SfCarouselRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) [0x000a3] in <7b928492986e4ddaabcc39b707c50172>:0

I'm pretty sure that the more complex styling problem will be solved as soon as I get this to work.

Cloud you have another look to the source code?

Thank you very much.


Alex


TO Toppreise June 23, 2017 01:17 PM UTC

Is it possible that my Xamarin Forms Version causes the issues?

Xamarin Studio Community
Version 6.3 (build 864)
Installation UUID: xyz
Runtime:
    Mono 5.2.0.179 (2017-04/4498dc4) (64-bit)
    GTK+ 2.24.23 (Raleigh theme)

    Package version: 502000179

NuGet
Version: 3.5.0.0

Xamarin.Profiler
'/Applications/Xamarin Profiler.app' not found

Xamarin.Android
Version: 7.4.0.2 (Xamarin Studio Community)
Android SDK: /Users/xyz/Library/Developer/Xamarin/android-sdk-macosx
    Unterstützte Android-Versionen:
        6.0 (API-Ebene 23)
        7.1 (API-Ebene 25)

Version der SDK-Tools: 25.2.5
Version der SDK-Plattformtools: 25.0.3
Version der SDK-Buildtools: 23.0.2

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Android Designer EPL-Code ist hier verfügbar:
https://github.com/xamarin/AndroidDesigner.EPL

Apple Developer Tools
Xcode 8.3.3 (12175.1)
Build 8E3004b

Xamarin Inspector
Not Installed

Xamarin.Mac
Version: 3.6.0.4 (Xamarin Studio Community)

Xamarin.iOS
Version: 10.12.0.5 (Xamarin Studio Community)
Hash: 104e7b43
Branch: d15-3
Build date: 2017-06-08 14:59:48-0400

Build Information
Release ID: 603000864
Git revision: 6c2f6737278ccc3e81e12276d49c0d92f975f189
Build date: 2017-04-24 11:26:01-04
Xamarin addins: d8d46e577d8507c35260ce9d73df3c33415bb214
Build lane: monodevelop-lion-d15-1

Operating System
Mac OS X 10.12.5
Darwin xyz-Mac-mini.local 16.6.0 Darwin Kernel Version 16.6.0
    Fri Apr 14 16:21:16 PDT 2017
    root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64




RG Rajkumar Ganesamoorthy Syncfusion Team June 26, 2017 12:51 PM UTC

Hi Toppreise,

Thanks for your update.

We have checked the reported issue in our side. We suspect that the reported issue occurred due to issue with Xamarin.forms(from 2.3.5 pre2 version). Currently we are analyzing more details on this. We will provide more information about this issue on 27 june,2017.

Regards,
Rajkumar G



RK Rathana Kumar Sekar Syncfusion Team June 27, 2017 01:52 PM UTC

Hi Toppreise, 

We have checked the reported issue from our side and we were unable to reproduce the reported issue and we have attached the sample which we have checked the reported issue. Please find the sample from the below link. 

Please check the reported issue with attached sample and if the reported issue persists, could you please provide modified sample which replicates the reported issue. 

It will help us to provide appropriate solution on this. 

Regards,
Rathanakumar S. 



TO Toppreise June 28, 2017 01:34 PM UTC

Hi,

Thanks for your answer. I opened the project and tried to compile it. I get the message "/Users/.../Documents/Xamarin/CarouselTesting/iOS/AppDelegate.cs(29,29): Error CS0234: The type or namespace name 'XForms' does not exist in the namespace 'Syncfusion.SfCarousel' (are you missing an assembly reference?) (CS0234) (CarouselTesting.iOS)"


Do you know how I can fix this error? I added the package Syncfusion.Xamarin.SfCarousel.IOS


Thank you very much for your help.


Alex



TO Toppreise June 28, 2017 01:40 PM UTC

Hi,

ok - I fixed the problem with adding the  Syncfusion.Xamarin.SfCarousel package to the project.

The testproject works fine. I'll try to reproduce the error tomorrow.


Thanks again.


Alex



RK Rathana Kumar Sekar Syncfusion Team June 29, 2017 08:39 AM UTC

Hi Toppreise, 

Thanks for your update. 

We will wait until hear from you. 

Regards,
Rathanakumar S.
 



TO Toppreise June 29, 2017 09:11 AM UTC

Hi,

ok, I'm honest, this issue is driving me mad.. ;) The example you attached as .zip file is working fine. I was trying again different settings in my category view class and tested finally for 4 hours on the ContentPage class. The problem has to be somewhere in the Carousel plugin, because the data is showing fine in a ListView.

This version crashes with "Object reference not set to an instance of an object" at " at Syncfusion.SfCarousel.XForms.iOS.SfCarouselMapping.OnCarouselPropertiesChanged (System.String propertyName, Syncfusion.SfCarousel.XForms.SfCarousel formsCarousel, Syncfusion.SfCarousel.iOS.SFCarousel nativeCarousel) [0x00029] in <7b928492986e4ddaabcc39b707c50172>:0
  at Syncfusion.SfCarousel.XForms.iOS.SfCarouselRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) [0x000a3] in <7b928492986e4ddaabcc39b707c50172>:0
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x00110] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:188 "


<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="TPApp.gui.pages.PageHome"
             xmlns:local="clr-namespace:TPApp.gui.pages"
             xmlns:carousel="clr-namespace:TPApp.gui.pages.HomeCarousel"
             xmlns:lang="clr-namespace:TPApp.gui.lang;assembly=TPApp"
             xmlns:catview="clr-namespace:TPApp.gui.views.category;assembly=TPApp"
             xmlns:carouselsync="clr-namespace:Syncfusion.SfCarousel.XForms;assembly=Syncfusion.SfCarousel.XForms"
             BackgroundColor="{StaticResource tpAppBackgroundColor}">

              <ContentPage.Resources>
                <ResourceDictionary>
                    <DataTemplate x:Key="tpProductItemTemplate">

                                <Label Text="{Binding sProductName}" TextColor="Black" /> 

                    </DataTemplate>
                </ResourceDictionary>
              </ContentPage.Resources>


             <ListView x:Name="tpVCatList" HasUnevenRows="true">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout>

                                <Label Text="{Binding sName}"></Label>
                        
                                <carouselsync:SfCarousel x:Name="tpProductCarousel" HeightRequest="400" WidthRequest="400" BackgroundColor="Aqua" ItemTemplate="{StaticResource tpProductItemTemplate}" ItemsSource="{Binding aProducts}"/> 

                                <!-- <ListView ItemsSource="{Binding aProducts}" HasUnevenRows="true">
                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <ViewCell>
                                                <StackLayout>            
                                                    <Label Text="PRODUCT" TextColor="Blue" /> 
                                                    <Label Text="{Binding sProductName}" TextColor="Blue" /> 
                                                </StackLayout>    
                                            </ViewCell>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                 </ListView> -->
                                
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
             </ListView>
        
</ContentPage>





The following version works like charm:


<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="TPApp.gui.pages.PageHome"
             xmlns:local="clr-namespace:TPApp.gui.pages"
             xmlns:carousel="clr-namespace:TPApp.gui.pages.HomeCarousel"
             xmlns:lang="clr-namespace:TPApp.gui.lang;assembly=TPApp"
             xmlns:catview="clr-namespace:TPApp.gui.views.category;assembly=TPApp"
             xmlns:carouselsync="clr-namespace:Syncfusion.SfCarousel.XForms;assembly=Syncfusion.SfCarousel.XForms"
             BackgroundColor="{StaticResource tpAppBackgroundColor}">

              <ContentPage.Resources>
                <ResourceDictionary>
                    <DataTemplate x:Key="tpProductItemTemplate">

                                <Label Text="{Binding sProductName}" TextColor="Black" /> 

                    </DataTemplate>
                </ResourceDictionary>
              </ContentPage.Resources>


             <ListView x:Name="tpVCatList" HasUnevenRows="true">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout>

                                <Label Text="{Binding sName}"></Label>
                        
                                <!-- <carouselsync:SfCarousel x:Name="tpProductCarousel" HeightRequest="400" WidthRequest="400" BackgroundColor="Aqua" ItemTemplate="{StaticResource tpProductItemTemplate}" ItemsSource="{Binding aProducts}"/>  -->

                                <ListView ItemsSource="{Binding aProducts}" HasUnevenRows="true">
                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <ViewCell>
                                                <StackLayout>            
                                                    <Label Text="PRODUCT" TextColor="Blue" /> 
                                                    <Label Text="{Binding sProductName}" TextColor="Blue" /> 
                                                </StackLayout>    
                                            </ViewCell>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                 </ListView>
                                
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
             </ListView>
        
</ContentPage>



Did I miss somewhere a initialization oder something?

I checked the following based on the example you provided me:

- References are available, Packages are added, the Renderer is initialized in AppDelegate via
new SfCarouselRenderer()


Do you have any other ideas? :/

Thanks very much,

Alex



RK Rathana Kumar Sekar Syncfusion Team June 30, 2017 01:11 PM UTC

Hi Toppreise,

Thanks for your update.

We have checked the reported issue with provided code sample and we were unable to reproduce the reported issue from our side. We have attached the sample which we have checked the reported issue. Please find the sample from the below link.

Sample: http://www.syncfusion.com/downloads/support/forum/131094/ze/Carouseltest2079111435 

So, could you please check the reported issue with attached sample and if the reported issue persists, please provide the modified sample which replicates the reported issue.

It will help us to provide appropriate solution on this.

Regards,
Rathanakumar S. 


Loader.
Up arrow icon