kontent-ai / management-sdk-net

Kontent.ai Management .NET SDK
https://www.nuget.org/packages/Kontent.Ai.Management
MIT License
7 stars 30 forks source link

FromDynamic on TaxonomyElement produces RuntimeBinderException on Value #265

Open kylejuliandev opened 2 months ago

kylejuliandev commented 2 months ago

Description

Accessing the Value IEnumerable produces a RuntimeBinderException.

using Kontent.Ai.Management.Models.LanguageVariants.Elements;
using Kontent.Ai.Management.Models.Shared;
using Kontent.Ai.Management.Models.Types.Elements;

var taxonomy = new TaxonomyElement
{
    Element = Reference.ByCodename("my_taxonomy"),
    Value = [Reference.ByCodename("my_taxonomy_item_1")]
};

var taxonomy2 = (TaxonomyElement) TaxonomyElement.FromDynamic(taxonomy.ToDynamic(), ElementMetadataType.Taxonomy);

var value1 = taxonomy2.Value.First();

Exception message: 'Kontent.Ai.Management.Models.Shared.Reference' does not contain a definition for 'id'

Stack trace

at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at Kontent.Ai.Management.Models.LanguageVariants.Elements.BaseElement.<>c.<FromDynamic>b__6_5(Object identifier)
at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at Program.<Main>$(String[] args) in D:\repos\demo\KontentAiMigrationAssistant\KontentAiMigrationAssistant\Program.cs:line 42

I also tried with Reference.ById and Reference.ByExternalId for the Value item and all produced the same exception.

Test environment

pokornyd commented 2 months ago

hello and thanks for the submission, as well as the draft PR. I'll review the issue and the proposed changes but feel free to add further improvements before marking the PR for review.