SettingsPlugin: Calling AddOrUpdateValue with a string throws "Value of type String is not supported"
Calling AddOrUpdateValue with string type throws exception Value of type String is not supported.
Here’s how this is possible:
object strValue = "a";
CrossSettings.Current.AddOrUpdateValue(key, strValue);
This is because the implementation is using Type.GetTypeCode to get the primitive type, but this returns System.TypeCode.Object, and not System.TypeCode.String as you could expect.
Same issue is on iOS, it’s very similar code.
As a solution, maybe use Convert.GetTypeCode which correctly returns TypeCode.String?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 23 (6 by maintainers)
Commits related to this issue
- Enhance value checks #60 Don't allow nulls to be passed int. Ensure type is passed up when not supported. — committed to jamesmontemagno/SettingsPlugin by jamesmontemagno 7 years ago
- Merge pull request #66 from jamesmontemagno/enhance-value-checks Enhance value checks #60 — committed to jamesmontemagno/SettingsPlugin by jamesmontemagno 7 years ago
@opcodewriter I would simply do something like this as the non-generic version:
The already existing private AddOrUpdateValue is unchanged and handles all the cases, including the typecode specific ones. I don’t have any opinion about complex types, as they are not part of the current code.
Yes, i should pass typecode 😃 which i already have, will fix that.
You can’t pass it an object like that, you have to make it:
string strValue = “a”;