Comments (1)
Response received from Unity:
Thanks for submitting this issue. I've looked into the code example you've sent and the issue appears to be in your deserialization constructor. It appears that the code worked in our old 3.5 runtime purely out of luck, but items you pull from the SerializationInfo aren't guaranteed to have been deserialized before the end of the constructor.
public Scope(SerializationInfo info, StreamingContext context)
{
var keys = info.GetValue<List<string>>("keys");
var values = info.GetValue<List<Value>>("values");
vars = new Dictionary<string, Value>();
for (int i = 0; i < keys.Count; ++i)
{
vars.Add(keys[i], values[i]);
}
DefaultSpeaker = info.GetValue<object>("defaultSpeaker");
}
This code looks reasonable to me..you're using two lists to serialize a dictionary's keys and values, and then recreating the dictionary... but after discussing with other members of the .net community from mono and .netcore, it would appear that when you get the values and store it in the "values" the items are not guaranteed to be deserialized yet because we are still in the deserialization constructor of of Scope. This means we may (or may not) be adding null keys and values to the dictionary here. To manipulate the data in this way, you'll need to do this after deserialization is completed. This can be done by marking a function with OnDeserializedAttribute or by setting a DeserializationCallback.OnDeserialization.
Given your sample, I was able to get the test to pass making these changes. Maybe there is a more elegant way, but I added lists for the keys and values to the Scope, and then deserialized them with the deserialization constructor, and then recreated the dictionary with the OnDeserialized function.
private Dictionary<string, Value> vars;
//For serialization only
private List<string> _keys;
private List<Value> _values;
public Scope(SerializationInfo info, StreamingContext context)
{
_keys = info.GetValue<List<string>>("keys");
_values = info.GetValue<List<Value>>("values");
DefaultSpeaker = info.GetValue<object>("defaultSpeaker");
}
[OnDeserialized]
public void repopulateVars()
{
vars = new Dictionary<string, Value>();
for (int i = 0; i < _keys.Count; ++i)
{
vars.Add(_keys[i], _values[i]);
}
}
Again, Thank you so much for submitting this issue! even in cases where the new behavior is considered "correct" Its good that we're of these behavior differences.
-Michael DeRoy
from unity-rumor.
Related Issues (20)
- Consider the addition of enum arguments for some commands HOT 5
- Example crashes in Unity HOT 4
- ArgumentOutOfRangeException on example HOT 3
- Feature request: syntax highlighting/formatting for RumorScript HOT 3
- Feature request: full Unity example project HOT 2
- Add syntax highlighting support for VSCode
- Add syntax highlighting support for Sublime Text
- Add syntax highlighting support for Atom
- Conditional assignment? HOT 8
- Using 'say' command with variables HOT 2
- Add no_wait enum argument to Say/Add commands HOT 1
- Add cant_skip enum argument to Pause commands HOT 1
- Tokenizer not handling comma after non-quoted value correctly HOT 2
- elif and else don't work if there are empty lines
- Pause still continues after a choice is chosen
- Keywords are sometimes treated as variables
- Add continuous integration support
- Detect and import files with a .rumor extension HOT 1
- Add syntax highlighting support for Visual Studio HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unity-rumor.