kekekeks / XamlX

General purpose pluggable XAML compiler with no runtime dependencies.
MIT License
319 stars 55 forks source link

ArgumentOutOfRange exception in ResolveContentPropertyTransformer.Transform #109

Open ds1709 opened 7 months ago

ds1709 commented 7 months ago

There'e multiple scenarios when compilling axaml throws internal compiller error (ArgumentOutOfRangeException). This exception occures when you have in source axaml file any xml elements of types which has no Content property and has no any Add method, but contains any nested elements. I faced with this trying to add objects into DataGrid, but it reproduces for other object types.

How to Reproduce

Scenario 1 (DataGrid):

<DataGrid>
    <sys:Int32>1<sys:Int32>
</DataGrid>

Scenario 2 (Object):

<sys:Object>
    <sys:Int32>1<sys:Int32>
</sys:Object>

In both scenarios on compilling:

XamlTransformException: Internal compiler error: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index (ResolveContentPropertyTransformer) Line 37, position 6.

ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at XamlX.Transform.Transformers.ResolveContentPropertyTransformer.Transform(AstTransformationContext context, IXamlAstNode node) in D:\Git\AvaloniaUI\Avalonia\src\Markup\Avalonia.Markup.Xaml.Loader\xamlil.github\src\XamlX\Transform\Transformers\ResolveContentPropertyTransformer.cs
   ... <truncated>

Expected behavior

Compilation error No Content property or any Add methods found for type <type name>.

Additional info

More detaile here