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

System.InvalidCastException when transforming inline table syntax to model #47

Closed
wants to merge 1 commit into from

Conversation

0xced
Copy link
Contributor

@0xced 0xced commented Oct 26, 2022

I have added a new test: TestReflectionModelWithInlineTable which is basically a copy of TestReflectionModel but with the inline table syntax.

TestReflectionModel:

[[sub]]
id = "id1"
publish = true

[[sub]]
id = "id2"
publish = false

[[sub]]
id = "id3"

TestReflectionModelWithInlineTable:

sub = [ { id = "id1", publish = true }, { id = "id2", publish = false }, { id = "id3" } ]

With the inline table syntax, this exception is thrown:

System.InvalidCastException : Unable to cast object of type 'Tomlyn.Model.Accessors.ListDynamicAccessor' to type 'Tomlyn.Model.Accessors.ObjectDynamicAccessor'.

At line 72 of SyntaxToModelTransform.cs:

var objectAccessor = ((ObjectDynamicAccessor)_currentObjectAccessor!);

This is not an obvious bug to fix (at least for me) but I chose to open a draft pull request anyway because I think this new test is a good starting point to discuss the issue.

…ormation

This exception is thrown:
> System.InvalidCastException : Unable to cast object of type 'Tomlyn.Model.Accessors.ListDynamicAccessor' to type 'Tomlyn.Model.Accessors.ObjectDynamicAccessor'.

At line 72 of SyntaxToModelTransform.cs:
```csharp
var objectAccessor = ((ObjectDynamicAccessor)_currentObjectAccessor!);
```
xoofx added a commit that referenced this pull request Oct 27, 2022
@xoofx
Copy link
Owner

xoofx commented Oct 27, 2022

This is not an obvious bug to fix (at least for me) but I chose to open a draft pull request anyway because I think this new test is a good starting point to discuss the issue.

That was not obvious for me as well. I haven't touched this code for a while, so it's easy to forget the details! 😅

But fortunately, that was an easy fix, I pushed the commit d64a5d2 with your test.

Thanks for reporting this!

@xoofx xoofx closed this Oct 27, 2022
@0xced 0xced deleted the TestReflectionModelWithInlineTable branch October 27, 2022 19:02
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

Successfully merging this pull request may close these issues.

2 participants