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

Error thrown when adding new value to a <string, int> dictionary through the ModConfig UI #692

Closed
atenfyr opened this issue Oct 12, 2019 · 7 comments

Comments

@atenfyr
Copy link

atenfyr commented Oct 12, 2019

Description

Attempting to add a new field to a <String, int> dictionary through the ModConfig UI results in the error "Cannot populate JSON object onto type 'System.String'" thrown.

Log File

client.log

Steps to Reproduce

  1. Create a mod with a config file which contains a dictionary mapping Strings to ints.
  2. Click the Add button (marked with a plus sign).

Expected behavior

A blank key mapped to a blank value should be added to the dictionary and displayed in the UI.

Actual behavior

The error "Cannot populate JSON object onto 'System.String'." is thrown and displayed in the notification bar. The dictionary and the UI are not noticeably modified in any other way.

Reproduction frequency

Consistently.

Additional Information

In issue #626, the sample mod I attached (DictionaryYikes.zip) which worked at the time it was created (tModLoader v0.11.3) now produces the same error consistently (tModLoader v0.11.5), meaning that this is likely not my own mistake.

@direwolf420
Copy link
Contributor

direwolf420 commented Oct 12, 2019

String or string? string is null by default hence the error maybe.
Do you have a [DefaultDictionaryKeyValue("")] attribute above your dictionary declaration?
I can confirm your error occurs when I don't use this attribute, and doesn't occur if I use it

@atenfyr atenfyr changed the title Error thrown when adding new value to a <String, int> dictionary through the ModConfig UI Error thrown when adding new value to a <string, int> dictionary through the ModConfig UI Oct 12, 2019
@atenfyr
Copy link
Author

atenfyr commented Oct 12, 2019

String or string? string is null by default hence the error maybe.
Do you have a [DefaultDictionaryKeyValue("")] attribute above your dictionary declaration?
I can confirm your error occurs when I don't use this attribute, and doesn't occur if I use it

Yeah, I haven't written anything in C# for a while, so my bad with the capitalization.
Is DefaultDictionaryKeyValue a new feature? It doesn't seem to be listed in the list of things that mod authors must change.

@direwolf420
Copy link
Contributor

@atenfyr
Copy link
Author

atenfyr commented Oct 12, 2019

It was added in 0.11.4
https://github.com/tModLoader/tModLoader/blob/v0.11.4/ExampleMod/ExampleConfig.cs?ts=4#L317

It would be ideal if there was a default that it lied back on, but thank you!

@atenfyr atenfyr closed this as completed Oct 12, 2019
@direwolf420
Copy link
Contributor

"ModConfig now supports default values for reference fields, greatly simplifying ModConfig code"
from 0.11.4 changelogs
basically just look at ExampleConfig again

@direwolf420
Copy link
Contributor

direwolf420 commented Oct 12, 2019

And there is a default for primitive types
string isn't one of them, it can be null when you initialize it

int i; //implicitely 0
string s; //null

JavidPack added a commit that referenced this issue Oct 13, 2019
@JavidPack
Copy link
Collaborator

This is a bug, thanks, fixed. Having to use DefaultDictionaryKeyValue is not intended.

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