question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calling AddOrUpdateValue with a string throws "Value of type String is not supported"

See original GitHub issue

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.

https://github.com/jamesmontemagno/SettingsPlugin/blob/master/src/Plugin.Settings.Android/Settings.cs#L207

Same issue is on iOS, it’s very similar code.

As a solution, maybe use Convert.GetTypeCode which correctly returns TypeCode.String?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:23 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Tornhoofcommented, May 8, 2017

@opcodewriter I would simply do something like this as the non-generic version:

public bool AddOrUpdateValue(string key, object value)
{
  if(value == null)
  {
    throw new ArgumentNullException(nameof(value));
  }
   return AddOrUpdateValue(key, value, Type.GetTypeCode(value.GetType()));
}

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.

1reaction
jamesmontemagnocommented, May 8, 2017

Yes, i should pass typecode 😃 which i already have, will fix that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Throwing exceptions in application configuration providers
class Configuration string GetValue(string key); // presence ... add only if not present void AddOrUpdateValue(string key, string value); ...
Read more >
mysql - How to fix "Incorrect string value" errors?
MySQL's utf-8 types are not actually proper utf-8 – it only uses up to three bytes per character and supports only the Basic...
Read more >
Solved: Update Item SP Error - Property selection is not s...
Property selection is not supported on values of type 'String'. ... Is this the reason why I wasn't able to call/select the JSON...
Read more >
Posibble to store all data under one excel sheet?
So my test case for POST or PUT just call individual data file. ... int end = 1; //values to new excel file...
Read more >
Visual Studio 2013 and .NET 4.5 Expert Cookbook
though the breakpoint exists in the code, it is marked as disabled, and hence the program ... public bool AddOrUpdateValue(string key, object value)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found