# "Element was referenced before it was initialized" scope issue

**URL:** <https://forums.fusetools.com/t/element-was-referenced-before-it-was-initialized-scope-issue/5124>\
**Category:** How-to Discussions\
**Created:** [March 31, 2016, 10:09pm UTC](https://forums.fusetools.com/t/element-was-referenced-before-it-was-initialized-scope-issue/5124 "2016-03-31T22:09:22Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fernando\_Lins](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/fernando_lins/32/597_2.png) [@Fernando\_Lins](https://forums.fusetools.com/u/Fernando_Lins)\
**Post date:** [March 31, 2016, 10:09pm UTC](https://forums.fusetools.com/t/element-was-referenced-before-it-was-initialized-scope-issue/5124/1 "2016-03-31T22:09:22Z")

</div>

Hi!

I’m having trouble understanding the scope in which `InnerClass` and `Class` are supposed to work. Would you kindly explain why the following code…

```auto
<SmallBlock>
    <Text Value="Tema" Alignment="CenterLeft"/>
    <Panel Alignment="CenterRight">

        <Circle ux:Class="ColorCircle" Width="38" Height="38" isActive="false" ux:Name="_thisColorCircle" Margin="12,0,0,0" themeState="Color1">
            <bool ux:Property="isActive" />
            <string ux:Property="themeState" />

            <WhileTrue Value="{Property _thisColorCircle.isActive}">
                <Circle Color="{Property _thisColorCircle.Color}">
                    <Stroke Width="3" Color="#FFF" />
                    <DropShadow Angle="0" Spread="0.1" Distance="0" Size="4" Color="#0004" />
                </Circle>
            </WhileTrue>

            <WhileFalse Value="{Property _thisColorCircle.isActive}">
                <Circle Color="{Property _thisColorCircle.Color}"/>
                <Change Target="_thisColorCircle.Opacity" Value="0.5" Duration="0.5" />
            </WhileFalse>

            <Clicked>
                <Set Target="stTheme.Active" Value="{Property _thisColorCircle.themeState}" />
            </Clicked>
        </Circle>

        <StackLayout Orientation="Horizontal" />
        <ColorCircle Color="{Resource oceano00}" ux:Name="btColor1" themeState="Color1"/>
        <ColorCircle Color="{Resource dourado00}" ux:Name="btColor2" themeState="Color2"/>
        <ColorCircle Color="{Resource vermelho00}" ux:Name="btColor3" themeState="Color3"/>
        <ColorCircle Color="{Resource roxo00}" ux:Name="btColor4" themeState="Color4"/>

        <StateGroup ux:Name="stTheme" Active="Color1">
            <State ux:Name="Color1">
                <Change Target="btColor1.isActive" Value="true" />
            </State>
            <State ux:Name="Color2">
                <Change Target="btColor2.isActive" Value="true" />
            </State>
            <State ux:Name="Color3">
                <Change Target="btColor3.isActive" Value="true" />
            </State>
            <State ux:Name="Color4">
                <Change Target="btColor4.isActive" Value="true" />
            </State>
        </StateGroup>

    </Panel>
</SmallBlock>

```

… gives me this error: `TabConfiguracoes.ux(81): E8001: 'stTheme' declared in TabConfiguracoes.ux(91) is a member 'MainView' and cannot be accessed from 'ColorCircle'. To make this work, consider making 'ColorCircle' an ux:InnerClass of 'MainView'. TowardDemo: E0000: Object reference not set to an instance of an object.` And when I follow its instructions (moving the block of code to MainView.ux and turning it into an `ux:InnerClass`) Preview gives me a new error?:

```auto
Element 'new_MainView.ColorCircle' was referenced before it was initialized

```

How should I solve this and why is `stTheme` not within `ColorCircle`'s reach? They are declared together inside the same Panel.

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [April 1, 2016, 5:26pm UTC](https://forums.fusetools.com/t/element-was-referenced-before-it-was-initialized-scope-issue/5124/2 "2016-04-01T17:26:51Z")

</div>

Hi!

`ux:Class` creates a completely independent class, that cannot reach anything outside itself. The fact that you declared it inside the panel doesn’t matter. You can move it to a separate file if you want.

However, `ux:InnerClass` is different. It cares about where it is declared, and can access symbols from that scope. To return the favor, you can only use it in that scope.

As the error message says, you need to change it to `ux:InnerClass` in order for it to reach symbols in the context it is declared.

To fix your problem, simply change `ux:Class="ColorCircle"` to `ux:InnerClass="ColorCircle"`

---

<div class="post-metadata">

**Author:** ![Fernando\_Lins](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/fernando_lins/32/597_2.png) [@Fernando\_Lins](https://forums.fusetools.com/u/Fernando_Lins)\
**Post date:** [April 1, 2016, 5:49pm UTC](https://forums.fusetools.com/t/element-was-referenced-before-it-was-initialized-scope-issue/5124/3 "2016-04-01T17:49:27Z")

</div>

Hi Anders,

If I do that, the compiler throws me this error:

```auto
...\build\Local\Preview14\cache\MainView.g.uno(2328.26): E2009: Call to 'Fuse.Controls.PropertyBinding<Fuse.Triggers.State>(Uno.UX.Property<Fuse.Triggers.State>,Uno.UX.Property<Fuse.Triggers.State>)' has some invalid arguments (TowardDemo_FuseTriggersActionsSet1_FuseTriggersState_Value_Property,TowardDemo_ColorCircle_string_themeState_Property)

```

I’m not exactly sure what this means but I don’t see anything wrong with my `themeState` property.

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [April 1, 2016, 7:28pm UTC](https://forums.fusetools.com/t/element-was-referenced-before-it-was-initialized-scope-issue/5124/4 "2016-04-01T19:28:33Z")

</div>

The source and destination data types in a property binding must be identical.

Change:

```auto
<string ux:Property="themeState" />

```

To:

```auto
<State ux:Property="themeState" />

```

---

<div class="post-metadata">

**Author:** ![Fernando\_Lins](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/fernando_lins/32/597_2.png) [@Fernando\_Lins](https://forums.fusetools.com/u/Fernando_Lins)\
**Post date:** [April 1, 2016, 8:02pm UTC](https://forums.fusetools.com/t/element-was-referenced-before-it-was-initialized-scope-issue/5124/5 "2016-04-01T20:02:11Z")

</div>

Ok, that cleared the .g.uno error, but I still have issues. Preview says:

```auto
Element 'new_MainView.ColorCircle' was referenced before it was initialized

```

Here’s the error from Monitor:

```auto
ERROR: Element'new_MainView.ColorCircle' was referenced before it was initialized
    Outracks.Simulator.Runtime.VariableNotBound occured.
       at Outracks.Simulator.Runtime.Environment.GetValue(Variable variable) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno:line 42
       at Outracks.Simulator.Runtime.Environment.GetValue(Variable variable) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno:line 40
       at Outracks.Simulator.Runtime.Environment.GetValue(Variable variable) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno:line 40
       at Outracks.Simulator.Runtime.Environment.GetValue(Variable variable) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno:line 40
       at Outracks.Simulator.Runtime.ScopeClosure.Evaluate(ReadVariable e) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 136
       at Outracks.Simulator.Bytecode.Expression.Match<a href="Func`2 a1, Func`2 a2, Func`2 a3, Func`2 a4, Func`2 a5, Func`2 a6, Func`2 a7, Func`2 a8, Func`2 a9, Func`2 a10, Func`2 a11, Func`2 a12, Func`2 a13, Func`2 a15, Func`2 a16">T</a> in C:\ProgramData\Uno\Packages\Outracks.Simulator.Protocol.Uno\0.0.0\Bytecode\$.uno#1:line 99
       at Outracks.Simulator.Runtime.ScopeClosure.Evaluate(Expression expression) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 131
       at Outracks.Simulator.Runtime.ScopeClosure.Evaluate(CallLambda i) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 163
       at Outracks.Simulator.Bytecode.Expression.Match<a href="Func`2 a1, Func`2 a2, Func`2 a3, Func`2 a4, Func`2 a5, Func`2 a6, Func`2 a7, Func`2 a8, Func`2 a9, Func`2 a10, Func`2 a11, Func`2 a12, Func`2 a13, Func`2 a15, Func`2 a16">T</a> in C:\ProgramData\Uno\Packages\Outracks.Simulator.Protocol.Uno\0.0.0\Bytecode\$.uno#1:line 106
       at Outracks.Simulator.Runtime.ScopeClosure.Evaluate(Expression expression) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 131
       at Outracks.Simulator.Runtime.ScopeClosure.Execute(Lambda lambda, Object[] arguments) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 105
       at Outracks.Simulator.Runtime.LambdaClosure.Func(Object a1) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 341
       at Outracks.Simulator.Runtime.ScopeClosure.Execute(Object lambda, Object[] arguments) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 221
       at Outracks.Simulator.Runtime.ScopeClosure.Evaluate(CallLambda i) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 163
       at Outracks.Simulator.Bytecode.Expression.Match<a href="Func`2 a1, Func`2 a2, Func`2 a3, Func`2 a4, Func`2 a5, Func`2 a6, Func`2 a7, Func`2 a8, Func`2 a9, Func`2 a10, Func`2 a11, Func`2 a12, Func`2 a13, Func`2 a15, Func`2 a16">T</a> in C:\ProgramData\Uno\Packages\Outracks.Simulator.Protocol.Uno\0.0.0\Bytecode\$.uno#1:line 106
       at Outracks.Simulator.Runtime.ScopeClosure.Evaluate(Expression expression) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 131
       at Outracks.Simulator.Runtime.ScopeClosure.Execute(IEnumerable<code>1 statements) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 117
       at Outracks.Simulator.Runtime.ScopeClosure.Execute(Lambda lambda, Object[] arguments) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 107
       at Outracks.Simulator.Runtime.LambdaClosure.Func(Object a1) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 341
       at Outracks.Simulator.Runtime.LambdaClosure.Action(Object a1) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 321
       at Outracks.Simulator.Runtime.ScopeClosure.Execute(Object lambda, Object[] arguments) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 231
       at Outracks.Simulator.Runtime.ScopeClosure.Evaluate(CallLambda i) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 163
       at Outracks.Simulator.Bytecode.Expression.Match<a href="Func&lt;/code&gt;2 a1, Func&lt;code&gt;2 a2, Func&lt;/code&gt;2 a3, Func&lt;code&gt;2 a4, Func&lt;/code&gt;2 a5, Func&lt;code&gt;2 a6, Func&lt;/code&gt;2 a7, Func&lt;code&gt;2 a8, Func&lt;/code&gt;2 a9, Func&lt;code&gt;2 a10, Func&lt;/code&gt;2 a11, Func&lt;code&gt;2 a12, Func&lt;/code&gt;2 a13, Func&lt;code&gt;2 a15, Func&lt;/code&gt;2 a16">T</a> in C:\ProgramData\Uno\Packages\Outracks.Simulator.Protocol.Uno\0.0.0\Bytecode\$.uno#1:line 106
       at Outracks.Simulator.Runtime.ScopeClosure.Evaluate(Expression expression) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 131
       at Outracks.Simulator.Runtime.ScopeClosure.Execute(IEnumerable`1 statements) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 117
       at Outracks.Simulator.Runtime.ScopeClosure.Execute(Lambda lambda, Object[] arguments) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 107
       at Outracks.Simulator.Runtime.VirtualMachine.Execute(IReflection reflection, Lambda lambda, Object[] arguments) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 78
       at Outracks.Simulator.Runtime.VirtualMachine.Execute(Lambda lambda, Object[] arguments) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 73
       at Outracks.Simulator.Reifying.OnEnterState() in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\$.uno#1:line 420
       at Outracks.Simulator.Application.SetState(State nextState) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\$.uno:line 136
       at Outracks.Simulator.Application.OnUpdate() in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\$.uno:line 126
       at Fuse.App.Update() in C:\ProgramData\Uno\Packages\Fuse.Desktop\0.26.10\$.uno:line 48

```

Here’s the full code for this Page: [[http://pastebin.com/qQsW2xMB](http://pastebin.com/qQsW2xMB)]

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [April 1, 2016, 9:40pm UTC](https://forums.fusetools.com/t/element-was-referenced-before-it-was-initialized-scope-issue/5124/6 "2016-04-01T21:40:41Z")

</div>

Hi!

Looks like you’ve hit a bug in Fuse. Can you provide a full test project please?

You can upload here: [https://www.dropbox.com/request/ZgndLtJQm5eGzG9cicGK](https://www.dropbox.com/request/ZgndLtJQm5eGzG9cicGK)

---

<div class="post-metadata">

**Author:** ![Fernando\_Lins](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/fernando_lins/32/597_2.png) [@Fernando\_Lins](https://forums.fusetools.com/u/Fernando_Lins)\
**Post date:** [April 4, 2016, 11:23pm UTC](https://forums.fusetools.com/t/element-was-referenced-before-it-was-initialized-scope-issue/5124/7 "2016-04-04T23:23:26Z")

</div>

Hi Anders, I’ve uploaded a case to the Dropbox link, named “InnerClassError\_86fernandolins.zip” (86fernandolins is my Slack nickname).

There are two things you should try:

1. Run the Preview as it is so you will get this error:

```auto
InnerClassError\FirstTab.ux(26): E8001: 'stTheme' declared in FirstTab.ux(36) is a member 'MainView' and cannot be accessed from 'ColorCircle'. To make this work, consider making 'ColorCircle' an ux:InnerClass of 'MainView'.
InnerClassError: E0000: Object reference not set to an instance of an object.

```

1. On line 9 of “FirstTab.ux” file, change `<Circle ux:Class="ColorCircle" ...` to `<Circle ux:InnerClass="ColorCircle" ...` so you will get this error:

```auto
Element 'new_MainView.ColorCircle' was referenced before it was initialized

```

Same error will show up if you move the whole `ColorCircle` declaration to MainView.ux and declare it as an `ux:Class`.

---

<div class="post-metadata">

**Author:** ![Fernando\_Lins](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/fernando_lins/32/597_2.png) [@Fernando\_Lins](https://forums.fusetools.com/u/Fernando_Lins)\
**Post date:** [April 6, 2016, 6:09pm UTC](https://forums.fusetools.com/t/element-was-referenced-before-it-was-initialized-scope-issue/5124/8 "2016-04-06T18:09:29Z")

</div>

Just tried the code on 0.12 and the same issues as above happen ^

---

<div class="post-metadata">

**Author:** ![Carla\_Andia](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/carla_andia/32/340_2.png) [@Carla\_Andia](https://forums.fusetools.com/u/Carla_Andia)\
**Post date:** [June 6, 2016, 10:07pm UTC](https://forums.fusetools.com/t/element-was-referenced-before-it-was-initialized-scope-issue/5124/9 "2016-06-06T22:07:07Z")

</div>

Hi,

I recently update my Fuse version, and now I have this issue when running the app:

“Element ‘pagActividad’ was referenced before it was initialized”

I didn’t have this problem before updating, and the order of pages is important, because it shows movement. Any suggestions?, please.

```auto
<PageControl ux:Name="actPage" Active="pagRamas" Interaction="None">
    ...
    <Page ux:Name="pagCalendario">
        <ux:Include File="Calendar.ux" />
        <Calendar/>

        <WhileInactive>
            <Change pagCalendario.IsEnabled="false"/>
            <Change pagCalendario.Visibility="Hidden"/>
        </WhileInactive>

        <WhileActive>
            <Change pagCalendario.IsEnabled="true"/>
            <Change pagCalendario.Visibility="Visible"/>
        </WhileActive>
    </Page>

    <Page ux:Name="pagActividad">
        <DockPanel>
        ...
       </DockPanel>
    </Page>
</PageControl>

```

```auto
<Panel ux:InnerClass="Calendar">
    ...
  <DockPanel Padding="0,2" Margin="0,10" IsEnabled="{valido}">
      <StackPanel>
          <Circle Color="{color}">
              <Text Value="{dia}" Padding="3" TextAlignment="Center" TextColor="{textColor}"/>
          </Circle>

          <Clicked>
              <Callback Handler="{setDay}" />
              <Set Target="actPage.Active" Value="pagActividad" />
          </Clicked>
      </StackPanel>
  </DockPanel>
</Panel>

```

---

<div class="post-metadata">

**Author:** ![LuisRodriguezLD](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/luisrodriguezld/32/616_2.png) [@LuisRodriguezLD](https://forums.fusetools.com/u/LuisRodriguezLD)\
**Post date:** [August 8, 2016, 4:59pm UTC](https://forums.fusetools.com/t/element-was-referenced-before-it-was-initialized-scope-issue/5124/10 "2016-08-08T16:59:13Z")

</div>

Hello.

Has this been fixed? I´m still getting the error. Could be me tho…

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [August 8, 2016, 5:11pm UTC](https://forums.fusetools.com/t/element-was-referenced-before-it-was-initialized-scope-issue/5124/11 "2016-08-08T17:11:15Z")

</div>

Hi,

We haven’t seen this issue. If this is still a problem in the latest version, can you please provide a complete test project that reproduces the issue? Thanks.

---

<div class="post-metadata">

**Author:** ![LuisRodriguezLD](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/luisrodriguezld/32/616_2.png) [@LuisRodriguezLD](https://forums.fusetools.com/u/LuisRodriguezLD)\
**Post date:** [August 8, 2016, 5:39pm UTC](https://forums.fusetools.com/t/element-was-referenced-before-it-was-initialized-scope-issue/5124/12 "2016-08-08T17:39:09Z")

</div>

Hello.

I sent a small example through Fuse´s dropbox. Not sure what’s going on.

---

<div class="post-metadata">

**Author:** ![LuisRodriguezLD](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/luisrodriguezld/32/616_2.png) [@LuisRodriguezLD](https://forums.fusetools.com/u/LuisRodriguezLD)\
**Post date:** [September 21, 2017, 6:12pm UTC](https://forums.fusetools.com/t/element-was-referenced-before-it-was-initialized-scope-issue/5124/13 "2017-09-21T18:12:07Z")

</div>

If anyone is having trouble with such error I recommend following the new thread -\> [https://www.fusetools.com/community/forums/howto\_discussions/uxproperty\_inside\_innerclass](https://www.fusetools.com/community/forums/howto_discussions/uxproperty_inside_innerclass)

And Fuselibs issue -\> [https://github.com/fusetools/fuselibs-public/issues/481](https://github.com/fusetools/fuselibs-public/issues/481)
