0

I am facing following exception during redirecting from one page to my another page.

Cannot create instance of type 'Microsoft.Phone.Shell.PhoneApplicationService' [Line: 38 Position: 23]

code below on first page:

NavigationService.Source = (new Uri("/SecondPage.xaml?selectedItem=" + myId, UriKind.RelativeOrAbsolute));

with the help of above uri i am calling my second page. according to some some solutions provided in stackOverflow, I have issue in my xaml page i am pasting below my piece of code of xaml page.

SupportedOrientations="PortraitOrLandscape"
shell:SystemTray.IsVisible="True" Loaded="PhoneApplicationPage_Loaded"
tools:TiltEffect.IsTiltEnabled="True" Orientation="Portrait" >
<phone:PhoneApplicationPage.Resources>
    <shell:ApplicationBar x:Key="SettingsBar" IsVisible="True"  Mode="Default">
        <shell:ApplicationBarIconButton x:Name="btnHome"  IconUri="Images/home.png" Text="home"  Click="btnHome_Click" />
        <shell:ApplicationBarIconButton x:Name="cot" IconUri="Images/toc.png" Text="toc"  Click="btnToc_Click"/>
        <shell:ApplicationBarIconButton x:Name="zoom" IconUri="Images/zoom.png" Text="zoom" Click="btnZoom_Click"/>
        <shell:ApplicationBarIconButton x:Name="setting" IconUri="Images/settings.png" Text="settings" Click="btnSettings_Click" />
        <shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarMenuItem x:Name="SettingBar_wb" Click="AppMenu_wb_Click" Text="See Wordbank" />
            <shell:ApplicationBarMenuItem x:Name="SettingBar_sn" Click="AppMenu_sn_Click" Text="See Notes, " />
            <shell:ApplicationBarMenuItem x:Name="SettingBar_hight" Click="AppMenu_hight_Click" Text="See Highlight" />
        </shell:ApplicationBar.MenuItems>
    </shell:ApplicationBar>
    <shell:ApplicationBar x:Key="AnnotatorBar" IsVisible="True" >
        <shell:ApplicationBarIconButton x:Name="notes"  IconUri="Images/notes.png" Text="note"  Click="btnNote_Click" />
        <shell:ApplicationBarIconButton x:Name="myhights" IconUri="Images/myghights.png" Text="highlight"  Click="btnHighlight_Click"/>
        <shell:ApplicationBarIconButton x:Name="definsed" IconUri="Images/definesed.png" Text="Define" Click="btnDefine_Click"/>
        <shell:ApplicationBarIconButton x:Name="webs" IconUri="Images/webs.png" Text="wordbank" Click="btnWordbank_Click" />
        <shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarMenuItem x:Name="AppMenu_SeeWordBank" Click="AppMenu_SeeWordBank_Click" Text="See Wordbank" />
            <shell:ApplicationBarMenuItem x:Name="AppMenu_SeeNotes" Click="AppMenu_SeeNotes_Click" Text="See Notes, " />
            <!--following is line 38 -->
            <shell:ApplicationBarMenuItem x:Name="AppMenu_SeeHighlights" Click="AppMenu_SeeHighlights_Click" Text="See Highlight" />
        </shell:ApplicationBar.MenuItems>
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.Resources>

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

Facing exception in App.g.cs

System.Windows.Application.LoadComponent(this, new System.Uri("/dbok;component/App.xaml", System.UriKind.Relative));
Ashish-BeJovial
  • 1,829
  • 3
  • 38
  • 62

1 Answers1

0

Yes, i have resolved the issue, it was my very small mistake and i really feeling bad for it because it was minor one mistake.

I did create a instance of the App class in my helper class so as you know App.xaml executes extremely first time so according to framework two instances of the App.xaml can not created.

I have modified my helper class.

From

App myApp = new App();

to

//Following is the right way to access the properties from the App.xaml page.
App thisApp = (App)System.Windows.Application.Current;
Ashish-BeJovial
  • 1,829
  • 3
  • 38
  • 62