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

InvalidCastException running the sample code #23

Closed
yychen opened this issue Feb 18, 2022 · 4 comments
Closed

InvalidCastException running the sample code #23

yychen opened this issue Feb 18, 2022 · 4 comments
Labels
invalid This doesn't seem right

Comments

@yychen
Copy link

yychen commented Feb 18, 2022

I'm trying to use this library in Unity. When I was trying out the sample code

var toml = @"global = ""this is a string""
# This is a comment of a table
[my_table]
key = 1 # Comment a key
value = true
list = [4, 5, 6]
";

// Converts the TOML string to a `TomlTable`
var model = Toml.ToModel(toml);
// Prints "this is a string"
Console.WriteLine(model["global"]);

It shows InvalidCastException while running Toml.ToModel(toml) during runtime.

InvalidCastException: Specified cast is not valid.
Tomlyn.Model.SyntaxToModelTransform.Visit (Tomlyn.Syntax.KeyValueSyntax keyValue) (at D:/a/Tomlyn/Tomlyn/src/Tomlyn/Model/SyntaxToModelTransform.cs:72)
Tomlyn.Syntax.KeyValueSyntax.Accept (Tomlyn.Syntax.SyntaxVisitor visitor) (at D:/a/Tomlyn/Tomlyn/src/Tomlyn/Syntax/KeyValueSyntax.cs:97)
Tomlyn.Syntax.SyntaxVisitor.DefaultVisit (Tomlyn.Syntax.SyntaxNode node) (at D:/a/Tomlyn/Tomlyn/src/Tomlyn/Syntax/SyntaxVisitor.cs:100)
Tomlyn.Syntax.SyntaxVisitor.Visit (Tomlyn.Syntax.SyntaxList list) (at D:/a/Tomlyn/Tomlyn/src/Tomlyn/Syntax/SyntaxVisitor.cs:12)
Tomlyn.Syntax.SyntaxList.Accept (Tomlyn.Syntax.SyntaxVisitor visitor) (at D:/a/Tomlyn/Tomlyn/src/Tomlyn/Syntax/SyntaxList.cs:32)
Tomlyn.Syntax.SyntaxVisitor.DefaultVisit (Tomlyn.Syntax.SyntaxNode node) (at D:/a/Tomlyn/Tomlyn/src/Tomlyn/Syntax/SyntaxVisitor.cs:100)
Tomlyn.Syntax.SyntaxVisitor.Visit (Tomlyn.Syntax.DocumentSyntax document) (at D:/a/Tomlyn/Tomlyn/src/Tomlyn/Syntax/SyntaxVisitor.cs:16)
Tomlyn.Toml.TryToModel[T] (Tomlyn.Syntax.DocumentSyntax syntax, T& model, Tomlyn.Syntax.DiagnosticsBag& diagnostics, Tomlyn.TomlModelOptions options) (at D:/a/Tomlyn/Tomlyn/src/Tomlyn/Toml.cs:226)
Tomlyn.Toml.ToModel[T] (Tomlyn.Syntax.DocumentSyntax syntax, Tomlyn.TomlModelOptions options) (at D:/a/Tomlyn/Tomlyn/src/Tomlyn/Toml.cs:204)
Tomlyn.Toml.ToModel[T] (System.String text, System.String sourcePath, Tomlyn.TomlModelOptions options) (at D:/a/Tomlyn/Tomlyn/src/Tomlyn/Toml.cs:158)
Tomlyn.Toml.ToModel (System.String text, System.String sourcePath, Tomlyn.TomlModelOptions options) (at D:/a/Tomlyn/Tomlyn/src/Tomlyn/Toml.cs:141)
NewBehaviourScript.Start () (at Assets/Scripts/NewBehaviourScript.cs:21)

I cannot reproduce this in Visual Studio, and I'm not very familiar with the .NET world. However, I can reproduce this using MonoDevelop, by downloading Visual Studio 2019 for Mac. It gives the same error.

@xoofx xoofx added the invalid This doesn't seem right label Feb 25, 2022
@xoofx
Copy link
Owner

xoofx commented Feb 25, 2022

Thanks, unfortunately, I'm unable to reproduce this by commit 60b7333
So I believe it is a misusage on your side, but can't tell from your log.
Closing for now.

@xoofx xoofx closed this as completed Feb 25, 2022
@yychen
Copy link
Author

yychen commented Mar 1, 2022

Can you test it on Unity3D? Or is this package not supposed to work with Unity? I tried the following method, both result into the same error:

  • Extract the nuget and put the Tomlyn.dll under netstandard2.0 into my empty Unity project
  • Imported NuGet for Unity and install tomlyn (0.12.0) from it

Both methods give me the same InvalidCastException.

BTW, I'm using Unity 2020.3.30f1

@xoofx
Copy link
Owner

xoofx commented Mar 5, 2022

Should be fixed by commit 21de2ab and available soon in 0.12.1+

@yychen
Copy link
Author

yychen commented Mar 7, 2022

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants