Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SendTags call results in System.InvalidCastException #311

Closed
ChrisMonson opened this issue Jun 29, 2022 · 3 comments
Closed

SendTags call results in System.InvalidCastException #311

ChrisMonson opened this issue Jun 29, 2022 · 3 comments

Comments

@ChrisMonson
Copy link

Description:

Making a call to OneSignal.Default.SendTags(myTags) results in a System.InvalidCastException with a message of "Specified cast is not valid."

Environment

Visual Studio 2022
Xamarin 17.2.0.177
OneSignalSDK.Xamarin 4.1.0
Installed via nuget

Steps to Reproduce Issue:

  1. Start a new Xamarin Forms blank project
  2. Install OneSignalSDK.Xamarin 4.1.0
  3. Add initialization code following documentation
  4. Make an awaited call to OneSignal.Default.SendTags and supply a dictionary with tags and values.

Anything else:

In digging through code for SendTags in the Android implementation, it appears that in November the method was changed from directly supplying a string of JSON data, to serializing the dictionary to a string and then attempting to cast it to a JSONObject.

OneSignalNative.SendTags((JSONObject)Json.Serialize(tags), handler);

This throws an invalid cast exception as it can't cast from the string returned from the serializer to JSONObject. Perhaps a better approach would be to use the JSONObject constructor that accepts a JSON string as a parameter?

An additional note is that due to a bug in Xamarin.Android at the moment, the exception is currently being returned as a null reference exception if it is awaited and not wrapped in a try/catch.

Stack Trace:
at OneSignalSDK.Xamarin.OneSignalImplementation.SendTags (System.Collections.Generic.Dictionary`2[TKey,TValue] tags) [0x00010] in /Users/tanay/Desktop/OneSignal/OneSignal-Xamarin-SDK/OneSignalSDK.Xamarin.Android/OneSignalImplementation.cs:169
at OneSignalTest.App.OnStart () [0x0004f] in C:\dev\OneSignalTest\OneSignalTest\OneSignalTest\App.xaml.cs:35

Reproduction project attached.
OneSignalTest.zip

@ChrisMonson
Copy link
Author

As an additional note, this is broken in both the 4.0 and 4.1 versions of the SDK.

@kevin-david
Copy link
Contributor

For anyone who hits this, I've shared a version that has @ChrisMonson 's fix in #313 applied here: #313 (comment)

@brismithers
Copy link
Contributor

This has been fixed and released in 4.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants