AddShape null reference exception

Good morning,
with Xamarin.Forms 5.0.0.1931 and Syncfusion 18.4.0.42 adding a shape from code i get null exception:

Code:


this.sfImageEditor.AddShape(settings: new PenSettings() { Color = Color.Black, Mode = Mode.Stroke, Opacity = 1f, StrokeWidth = this.currentStrokeWidth });


Exception:

   System.NullReferenceException: 'Object reference not set to an instance of an object.'

   at Syncfusion.UI.Xaml.ImageEditor.SfImageEditor.AddShape(ShapeType shapeType, PenSettings penSettings)
   at XXXX.Pages.ImageEditorPage.AddBrushShape()



Please it's urgent,
Thanks

13 Replies 1 reply marked as answer

MN Marco Negroni February 10, 2021 01:10 PM UTC

Platform UWP


ET Eswaran Thirugnanasambandam Syncfusion Team February 11, 2021 01:06 PM UTC

Hi Marco Negroni, 
 
Thanks for contacting Syncfusion support. 
 
We have checked the reported issue and unable to reproduce the issue in our end. We have prepared a simple sample when adding shapes by using AddShape() method as you mentioned. Please get the sample from the below link. 
 
 
 We have checked with the below configuration. 
 
 Syncfusion Version: 18.4.0.42 
 
Xamarin Forms Version: 5.0.0.1931 
 
UWP Target version: Windows 10.0, Build 17763 
 
 So, could you please check the issue with the attached sample and let us know whether it is reproduced?     
 
 If the issue is not reproduced in the above sample, please revert us by modifying the sample based on your application along with the replication procedure. It will helpful for us to provide faster solution. 
 
Regards, 
Eswaran 



MN Marco Negroni replied to Eswaran Thirugnanasambandam February 11, 2021 03:04 PM UTC

Hi Marco Negroni, 
 
Thanks for contacting Syncfusion support. 
 
We have checked the reported issue and unable to reproduce the issue in our end. We have prepared a simple sample when adding shapes by using AddShape() method as you mentioned. Please get the sample from the below link. 
 
 
 We have checked with the below configuration. 
 
 Syncfusion Version: 18.4.0.42 
 
Xamarin Forms Version: 5.0.0.1931 
 
UWP Target version: Windows 10.0, Build 17763 
 
 So, could you please check the issue with the attached sample and let us know whether it is reproduced?     
 
 If the issue is not reproduced in the above sample, please revert us by modifying the sample based on your application along with the replication procedure. It will helpful for us to provide faster solution. 
 
Regards, 
Eswaran 


Good afternoon,
i found the problem, i made a custom toolbar so i removed the imageeditor toolbar items related to shapes and  text:

try the following code and you will get the exception:


using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Syncfusion.SfImageEditor.XForms;
using System.Reflection;

namespace IESample
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class GettingStarted : ContentPage
    {
        private float currentStrokeWidth = 10;

        public GettingStarted()
        {
            InitializeComponent();

            this.imageEditor.SetToolbarItemVisibility("Undo,Redo,Save,Reset,Opacity", false);

            this.imageEditor.ToolbarSettings.ToolbarItems.Remove(this.imageEditor.ToolbarSettings.ToolbarItems.Where(x => x.Name == "Text").First());
            this.imageEditor.ToolbarSettings.ToolbarItems.Remove(this.imageEditor.ToolbarSettings.ToolbarItems.Where(x => x.Name == "Shape").First());
            this.imageEditor.ToolbarSettings.ToolbarItems.Remove(this.imageEditor.ToolbarSettings.ToolbarItems.Where(x => x.Name == "Transform").First());
            this.imageEditor.ToolbarSettings.ToolbarItems.Remove(this.imageEditor.ToolbarSettings.ToolbarItems.Where(x => x.Name == "Effects").First());
            this.imageEditor.ToolbarSettings.ToolbarItems.Remove(this.imageEditor.ToolbarSettings.ToolbarItems.Where(x => x.Name == "Path").First());

            this.imageEditor.ColorPalette.Clear();
            this.imageEditor.ColorPalette.Add(Color.Black);
            this.imageEditor.ColorPalette.Add(Color.White);

            imageEditor.ImageLoaded += ImageEditor_ImageLoaded;
        }

        private void ImageEditor_ImageLoaded(object sender, ImageLoadedEventArgs args)
        {
            //this.imageEditor.AddShape(ShapeType.Circle,settings: new PenSettings() { Color = Color.Black, Mode = Mode.Stroke, Opacity = 1f, StrokeWidth = this.currentStrokeWidth });
        }

        private void Button_Clicked(object sender, EventArgs e)
        {
            this.imageEditor.AddShape(ShapeType.Path, settings: new PenSettings() { Color = Color.Green, Mode = Mode.Stroke, Opacity = 1f, StrokeWidth = this.currentStrokeWidth });
        }
    }


    class ImageModel
    {
        public ImageSource Image { get; set; }

        public ImageModel()
        {
            Assembly assembly = typeof(ImageModel).GetTypeInfo().Assembly;
            Image = ImageSource.FromResource("IESample.Image.jpeg", assembly);
        }
    }
}


MN Marco Negroni February 11, 2021 03:07 PM UTC

We dont want the image editor subtoolbars, because we made an external stroke width selector and other stuff.


MN Marco Negroni February 11, 2021 03:11 PM UTC

With:
Syncfusion Version: 18.3.0.40
Xamarin Forms Version: 4.7.0.1351

works fine.


With:

Syncfusion Version: 18.4.0.42
Xamarin Forms Version: 5.0.0.1931

doesn't work.


ET Eswaran Thirugnanasambandam Syncfusion Team February 12, 2021 05:41 PM UTC

Hi Marco Negroni, 
 
We have checked the reported problem with the given code snippet. We can reproduce the reported issue from our side, and we have already fixed this issue. The fix will be available in the upcoming weekly NuGet (Feb 16, 2021). 
 
Regards, 
Eswaran  



PM Peter Mortley February 13, 2021 03:42 PM UTC

I have the same problem relating to a custom tool bar adding text from code, getting a null exception,  Forms 5.0.0.1931 and Syncfusion 18.4.0.42. Hopefully the patch that addresses shapes will address Text too?


ET Eswaran Thirugnanasambandam Syncfusion Team February 15, 2021 11:30 AM UTC

Hi Peter Mortley, 
 
Yes, we have already considered “Exception is thrown when adding text from code when using custom toolbar” and the fix will be available in the upcoming weekly NuGet (Feb 16, 2021). 
 
Regards, 
Eswaran 



MN Marco Negroni replied to Eswaran Thirugnanasambandam February 17, 2021 08:30 AM UTC

Hi Peter Mortley, 
 
Yes, we have already considered “Exception is thrown when adding text from code when using custom toolbar” and the fix will be available in the upcoming weekly NuGet (Feb 16, 2021). 
 
Regards, 
Eswaran 


Thanks now works on UWP, but same problem on Android/IOS:

System.NullReferenceException: 'Object reference not set to an instance of an object.'


SS Sridevi Sivakumar Syncfusion Team February 18, 2021 06:43 AM UTC

Hi Marco Negroni,

We have already fixed the reported issue in Android and iOS platform, and the fix will be included in our next weekly NuGet, which is expected to be rolled out on Feb 23,2021.

Let us know if you need any further assistance.

Regards,
Sridevi S.
 



NA Natalia Alegria February 18, 2021 06:11 PM UTC

Hi,

I am still facing the same issue as Marco Negroni on UWP with Xamarin Forms 5.0.0.1931 and SfImageEditor 18.4.0.43.

Issues with rectangle, circle and text:
imageEditor.AddShape(ShapeType.Rectangle, new PenSettings() { Color = Color.Red, Mode = Mode.Stroke, Opacity = 1f, StrokeWidth = 10 });

Thanks



SS Sridevi Sivakumar Syncfusion Team February 19, 2021 12:12 PM UTC

Hi Natalia Alegria,

In UWP, we have already fixed that issue in UWP and moved fix in 18.4.0.43 version. And we have ensured the fix available in 18.4.0.43 version.

For Android and iOS, we will move this fix in Feb 23 weekly NuGet release.

Can you please share issue reproducing sample with replication procedure?
 This will be helpful for us to provide you better solution at the earliest.

Regards, 
Sridevi S. 



SS Sridevi Sivakumar Syncfusion Team February 23, 2021 10:59 AM UTC

Hi Peter Mortley,

We have fixed the reported “[Android,iOS] Exception is thrown when adding text from code when using custom toolbar” 
issue and the fix is included in our weekly NuGet of February 23, 2021.

NuGet Version: 18.4.0.44

We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.


Regards,

Sridevi S.    


Marked as answer
Loader.
Up arrow icon