Unhandled Exception when Clicking on Text Field to Send a Message

Hi Vassili,

Since we are not aware of your exact application situation, please share the
following information in order to test it further and have a potential solution sooner.   

i) Complete configuration of Sfchat with current page details.

ii) Xamarin forms version.

iii) iOS device details.

iv) Video of the issue, if possible.

v) Have you enabled safe area for the page ?


Regards,
Karthik Raja
 


10 Replies 1 reply marked as answer

VA Vassili April 5, 2021 11:44 AM UTC

Hi,

Unfortunately the Unhandled Exception below doesn't contain my code so there is no way to catch it.
Could you change the way it works to simply swallow it so that the app doesn't crash? Or in other words check for Null in Syncfusion.XForms.iOS.Chat.ChatEditorRenderer.GetChatControl ()  and if it's Null don't do anything?

It occurs sometimes when I quickly put mouse in the Chat Edit field using iOS simulator. Syncfusion version used: 19.1.0.54

I use it on a Mac for iOS part:

Message: Object reference not set to an instance of an object.
Source: Syncfusion.SfChat.XForms.iOS

  at Syncfusion.XForms.iOS.Chat.ChatEditorRenderer.GetChatControl () [0x00015] in <51c66f00aa8541f096f2168f44a937bd>:0 
  at Syncfusion.XForms.iOS.Chat.ChatEditorRenderer.OnEditorFocused (System.Object sender, Xamarin.Forms.FocusEventArgs e) [0x00008] in <51c66f00aa8541f096f2168f44a937bd>:0 
  at (wrapper delegate-invoke) System.EventHandler`1[Xamarin.Forms.FocusEventArgs].invoke_void_object_TEventArgs(object,Xamarin.Forms.FocusEventArgs)
  at Xamarin.Forms.VisualElement.OnFocused () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:990 
  at Xamarin.Forms.VisualElement.OnIsFocusedPropertyChanged (Xamarin.Forms.BindableObject bindable, System.Object oldvalue, System.Object newvalue) [0x00013] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1060 
  at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00120] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:512 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:446 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindablePropertyKey propertyKey, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:379 
  at Xamarin.Forms.Element.SetValueFromRenderer (Xamarin.Forms.BindablePropertyKey property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:254 
  at Xamarin.Forms.Platform.iOS.EditorRendererBase`1[TControl].OnStarted (System.Object sender, System.EventArgs eventArgs) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\EditorRenderer.cs:289 
  at UIKit.UITextView+_UITextViewDelegate.EditingStarted (UIKit.UITextView textView) [0x0000a] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/ios/native/UIKit/UITextView.g.cs:2757 
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:86 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:65 

Thanks, Vassili


VA Vassili April 5, 2021 12:25 PM UTC

Hi, I attached the screenshot.
Interestingly this happens not all the time but about 10-20 % of times when I open a chat window and click on the text area to send a message below the chat.
But: in case of a crash this area is not painted completely symmetric. Please see my screenshot: "Type a message" placeholder text is shown not in the middle of the area (when it's in the middle, there is no crash) but on top of it.
My Xamarin.Forms version is the latest: 5.0.0.2012
I'm using iPhone 12 Pro 14.4 Simulator on a MacOs Catalina 10.15.6
Please let me know if you'd like to see particular values of the Chat page. I also attached the .xaml file.

Thanks, Vassili
P.S. What do you mean by enabling the safe area for the page? How do I do that?

Attachment: Archive_9a49a41c.zip


VA Vassili April 5, 2021 12:40 PM UTC

P.S. Here are screenshots with "good" and "bad" cases: one can say beforehand if the crash will occur or not.
I also attached the data taken from the Chat.Editor.Focused += Editor_Focused; event handler, printing the details of FocusEventArgs. This event handler is triggered right before the crash.

Thanks, Vassili

Attachment: Archive_78304fb9.zip


VA Vassili April 5, 2021 05:07 PM UTC

Ok, a temporal workaround for me, is removing all the Event Handlers for "Focused" event.
One needs to use Reflection for this since it's a library code.
I used this piece to remove all of your focused event handlers: https://www.codeproject.com/Articles/103542/Removing-Event-Handlers-using-Reflection
Then I do this:
            RemoveEventHandler(Chat.Editor, "Focused");
            RemoveEventHandler(Chat.Editor, "Unfocused");
            RemoveEventHandler(Chat.Editor, "FocusChangeRequested");

This does work for me (no crashes anymore). Obviously this is an ugly solution so I am looking forward to your fix (the simplest for you would be just checking for null values inside of at Syncfusion.XForms.iOS.Chat.ChatEditorRenderer.GetChatControl ()  (this is where it crashes for me).

Thanks, Vassili



KK Karthikraja Kalaimani Syncfusion Team April 6, 2021 07:46 AM UTC

Hi Vassili,

Currently, we are preparing sample to reproduce the issue. We will update the details on or before 8th April 2021.

Regards,
Karthik Raja
 



CS Chandrasekar Sampathkumar Syncfusion Team April 8, 2021 08:08 PM UTC

Hi Vassili, 
Thank you for your patience. 
We have prepared simple sample based on the code snippet provided. We regret to let you know that we are not able to replicate the reported issue. We have attached the tested sample for your reference and you can download the same using the following link, 
Sample Link: Sample 
Could you please replicate the issue for us in the attached sample so that we can check on it and provide you solution at the earliest. 
Regards, 
Chandrasekar Sampathkumar 



VA Vassili April 8, 2021 10:30 PM UTC

Hi Chandrasekar,

Is it so important to repro this?
You know that sometimes there is a crash and also you have a stack trace, so you know exactly where in your code the app crashes (a null reference exception).
If you just add an "if object is null" there, the crash will be eliminated (however likely or unlikely it is). Are there any drawbacks in doing that?
Please let me know your thoughts.

Thanks, Vassili


CS Chandrasekar Sampathkumar Syncfusion Team April 12, 2021 04:54 AM UTC

Hi Vassili, 
Thank you for the update. 
We have added null check based on the stack trace in the method “ChatEditorRenderer.GetChatControl” and included the same in our source. The issue fix will be available in our next weekly nuget release which is scheduled to be rolled out on April 13, 2021. We appreciate your patience until then. 
Regards, 
Chandrasekar Sampathkumar 



VA Vassili April 12, 2021 11:06 AM UTC

Thanks a lot for the fix!
Meanwhile I'll try to repro using your sent chat project template and will update you if successful.

Thanks, Vassili


KK Karthikraja Kalaimani Syncfusion Team April 13, 2021 04:55 AM UTC

Hi vassili,

Thanks for the update. The weekly nuget has been published (19.1.0.56) with the null check possibilities codes and you can download from nuget.org. So, could you please check with the latest SfChat version and let us know the issue has fixed or not in your side?.

Regards,
Karthik Raja
 


Marked as answer
Loader.
Up arrow icon