Skip to content

BindingContextProvider throws exception in Unity2023 #53

Closed

Description

@Hellfim

Simple declaration of BindingContextProvider

<UnityMvvmToolkit.UITK.BindableUIElements.BindingContextProvider name="TestName"/>

Throws an exception in runtime when BindingContextProvider is created. As far as I was able to trace the problem - method Deserialize of BindingContextProvider receives a visualElement argument which is being cast to BindingContextProvider inside .As method extension, which throws an exception. Received argument has a type of VisualElement.

Stacktrace (truncated my invocation entry-point):
InvalidCastException: Specified cast is not valid.
(wrapper castclass) System.Object.__castclass_with_cache(object,intptr,intptr)
UnityMvvmToolkit.UITK.Extensions.VisualElementExtensions.As[T] (System.Object visualElement) (at ./Library/PackageCache/com.chebanovdd.unitymvvmtoolkit@1.1.7/Runtime/UITK/Extensions/VisualElementExtensions.Uxml.cs:12)
UnityMvvmToolkit.UITK.BindableUIElements.BindingContextProvider1+UxmlSerializedData[TBindingContext].Deserialize (System.Object visualElement) (at ./Library/PackageCache/com.chebanovdd.unitymvvmtoolkit@1.1.7/Runtime/UITK/BindableUIElements/Uxmls/BindingContextProvider.T.Uxml.cs:23) UnityEngine.UIElements.VisualElementAsset.Instantiate (UnityEngine.UIElements.CreationContext cc) (at <844b3559a9bf433db5c9639bc6cc5f04>:0) UnityEngine.UIElements.VisualTreeAsset.Create (UnityEngine.UIElements.VisualElementAsset asset, UnityEngine.UIElements.CreationContext ctx) (at <844b3559a9bf433db5c9639bc6cc5f04>:0) UnityEngine.UIElements.VisualTreeAsset.CloneSetupRecursively (UnityEngine.UIElements.VisualElementAsset root, System.Collections.Generic.Dictionary2[TKey,TValue] idToChildren, UnityEngine.UIElements.CreationContext context) (at <844b3559a9bf433db5c9639bc6cc5f04>:0)
UnityEngine.UIElements.VisualTreeAsset.CloneSetupRecursively (UnityEngine.UIElements.VisualElementAsset root, System.Collections.Generic.Dictionary`2[TKey,TValue] idToChildren, UnityEngine.UIElements.CreationContext context) (at <844b3559a9bf433db5c9639bc6cc5f04>:0)
UnityEngine.UIElements.VisualTreeAsset.CloneTree (UnityEngine.UIElements.VisualElement target, UnityEngine.UIElements.CreationContext cc) (at <844b3559a9bf433db5c9639bc6cc5f04>:0)
UnityEngine.UIElements.VisualTreeAsset.Instantiate () (at <844b3559a9bf433db5c9639bc6cc5f04>:0)
UnityEngine.UIElements.UIDocument.RecreateUI () (at <844b3559a9bf433db5c9639bc6cc5f04>:0)
UnityEngine.UIElements.UIDocument.set_visualTreeAsset (UnityEngine.UIElements.VisualTreeAsset value) (at <844b3559a9bf433db5c9639bc6cc5f04>:0)

Activity

  1. added a commit that references this issue on Aug 4, 2023
    bdde0e2
  2. Hellfim commented on Aug 4, 2023

    @Hellfim
    ContributorAuthor

    Not sure wether this would help, but declaring a CustomContextProvider like so

    public partial class CustomViewModelProvider : BindingContextProvider<CustomViewModel>
    

    Works fine and doesn't throw any exceptions

  3. ChebanovDD commented on Aug 4, 2023

    @ChebanovDD
    Collaborator

    Not sure wether this would help, but declaring a CustomContextProvider like so

    public partial class CustomViewModelProvider : BindingContextProvider<CustomViewModel>
    

    Works fine and doesn't throw any exceptions

    You didn't notice, but I had already uploaded the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions