Exception when switching Context in DataContextNodeConnectorInitializer thrown and not handled

Create issue
Issue #92 resolved
Former user created an issue

Trying to switch context in start function results in "throw InvalidOperationException("There is already an initialization registered for the connector");" which is not handled in the context setter.

Having two Context Holder, one consistent on a DontDestroyOnLoad Object with CreateContext set to true and another on a scene-specific object, which has autocreation turned off. in the Start-function of a script on the scene specific the context is tried to setup via:

SceneSpecificContextHolder.Context = StaticContextHolderScript.Instance.GetUserIdentityContext();

The Context is updated in the scene specific one, but due to the thrown exception the setters registered on the scene specifc context in the unity inspector stop working.

I added locally the line:

            this.initializer.RemoveInitialization(this);

in the DataContextNodeConnector.cs file behind line 105 (after removing the listerners of the old context) to discard pending initialization which cause the exception to be thrown, but I'm not sure whether or not this will cause bad side-effects, on first glance it works perfectly fine hereafter. Please check/update :) // alternatively this.initializer.ExecuteInitializations(); force initializing worked too

Comments (3)

  1. Christian Oeing repo owner

    Great, thanks a lot for your report! I will try to reproduce it in a unit test and fix it afterwards. Your solution sounds reasonable, I will try that one first. A fix will definitively make it into the next version 🙂

  2. Christian Oeing repo owner

    I could reproduce the issue with a unit test and fixed it exactly like you suggested. The pending initialization is useless if another one will be added. Thanks again for your report!

  3. Log in to comment