XamlSiteMapProvider

May 26, 2010 at 4:21 PM
Edited May 27, 2010 at 7:23 AM

Hi,

I've been trying to use the XamlSiteMapProvider as per Office2010 v2 sample but keep getting the following error:

 The tag 'XamlSiteMapProvider' does not exist in XML namespace 'clr-namespace:nRoute.SiteMaps;assembly=nRoute.Framework'. 

 

When I try using the xmlns prefix I get a similar error: 

The tag 'XamlSiteMapProvider' does not exist in XML namespace 'http://nRoute/schemas/2010/xaml'.

My App.xaml is included below:

<Application x:Class="<App Name>.UI.App" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:n="http://nRoute/schemas/2010/xaml" 
             >

    <Application.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="Assets/Converters.xaml" />
				<ResourceDictionary Source="Assets/Styles.xaml" />
				<ResourceDictionary Source="Assets/Desktop.xaml" />
			</ResourceDictionary.MergedDictionaries>
            
            <n:XamlSiteMapProvider x:Key="SiteMapProvider">

                <n:SiteMap>
                    <n:SiteMap.Areas>
                        <n:SiteArea Key="<Module Name>" InitializeOnLoad="False" RemoteUrl="/Modules/<App>.UI.<Module Name>.xap"/>
                    </n:SiteMap.Areas>
                    <n:SiteMap.RootNode>

                        <n:NavigationNode Title="Home" Url="Home">

                            <n:NavigationNode Title="Help">
                                <n:NavigationNode Title="About" Url="Help/About" />
                            </n:NavigationNode>

                            <n:NavigationNode Title="Tasks">
                                <n:NavigationNode Title="Order Search" Url="Content/OrderSearch"/>
                            </n:NavigationNode>


                            <n:NavigationNode Title="<Module Title">
                                <n:NavigationNode Title="Submit Order File(s)" Url="<Module Name>/SubmitOrderFile" SiteArea="<Module Name>"/>
                            </n:NavigationNode>

                        </n:NavigationNode>

                    </n:SiteMap.RootNode>
                </n:SiteMap>

            </n:XamlSiteMapProvider>
        </ResourceDictionary>
	</Application.Resources>

	<Application.ApplicationLifetimeObjects>
        <n:nRouteApplicationService SiteMapProvider="{StaticResource SiteMapProvider}"/>
    </Application.ApplicationLifetimeObjects>


</Application>
It's all very strange since at design time I get intellisense and everything but and build time it still claims the tag doesn't exist. What could I be doing wrong? Before you ask, yes the nRoute.Framework assembly is referenced - it is the latest (0.4.5) version.
I only intended to use this sitemap provider as a stopgap since we have a lot of dynamically loaded modules and I'd like to lazily discover what pages/sitemapnodes they offer. 

Any help would be appreciated.
    
		
			
				
				
				
			
            
            

                
                    
                        
                        
                    
                    

                        

                            
                                
                            

                            
                                
                            


                            
                                
                            

                        

                    
                

            
        
	

	
        
    


 The tag 'XamlSiteMapProvider' does not exist in XML namespace 'http://nRoute/schemas/2010/xaml'. 

 

 

Here's my App.xaml:

 

Coordinator
May 26, 2010 at 8:20 PM

Well, from your xaml I can see one problem - you've declared the XamlSiteMapProvider as a static-resource, however as I understand in Silverlight ApplicationLifetimeObjects are initialized much before static resources are availed. So I'd suggest place the XamlProvider declaration directly with the nRouteApplicationService:

<Application.ApplicationLifetimeObjects>
        
    <!-- BOOTSTRAPER -->
    <n:nRouteApplicationService>

        <!-- PROVIDER -->
        <n:XamlSiteMapProvider>
            <n:XamlSiteMapProvider.SiteMap>

                <!-- SITE MAP -->
                <n:SiteMap>
                        
                    <!-- AREAS -->
                    <n:SiteMap.Areas>
                        <n:SiteArea Key="Module" InitializeOnLoad="False" RemoteUrl="nRoute.Samples.SiteMapModule.xap"/>                            
                    </n:SiteMap.Areas>
                        
                    <!-- MAP -->
                    <n:SiteMap.RootNode>
                        <n:NavigationNode Title="Home" Url="Home">

                            <n:NavigationNode Title="Help">
                                <n:NavigationNode Title="About" Url="Help/About" />
                            </n:NavigationNode>

                            <n:NavigationNode Title="Module Content">
                                <n:NavigationNode Key="ModulePageNode" Title="Module Page" Url="Module/Page" SiteArea="Module"/>
                            </n:NavigationNode>

                        </n:NavigationNode>
                    </n:SiteMap.RootNode>
                        
                </n:SiteMap>

            </n:XamlSiteMapProvider.SiteMap>                
        </n:XamlSiteMapProvider>

    </n:nRouteApplicationService>
        
</Application.ApplicationLifetimeObjects>

Secondly, double check you have references to both System.Observable.dll [from Rx Framework] and System.Windows.Interactivity.dll [Version 4.0.5.0]. And as a guess, also ensure your are indeed using Silverlight's nRoute assembly and not WPF or WP7, plus if you are really using those angle-brackets in your SiteMap declarations just try changing them.

Also, I've spiked a small SiteMap's sample (its SiteMap is shown above) which you can download from here:

http://cid-587cbdf035b4a11d.skydrive.live.com/self.aspx/.Public/nRoute.Samples.SiteMapExample.zip

It's working on my machine, it should work with yours too. Let me if you can get things working.

Cheers,
Rishi

Coordinator
May 26, 2010 at 8:58 PM

BTW, you wrote ...

"I only intended to use this sitemap provider as a stopgap since we have a lot of dynamically loaded modules and I'd like to lazily discover what pages/sitemapnodes they offer."

Well, SiteMap already lazily discovers the pages/nodes - any external resource is not loaded unless something requests for it or you set InitializeOnLoad to be true. Further, if you wanted to assemble the SiteMap itself dynamically, that is also possible since you could write a custom SiteMap provider (say one that emits the SiteMap through a db).

Also, FYI:

- Whenever the SiteMap is loaded, a broadcasted is send on Channel<SiteMap>'s public channel
- Whenever a remote resource is loaded info about is broadcasted on Channel<LoadedResourceInfo>'s public channel
- Whenever an assembly is mapped info about is broadcasted using Channel<MappedAssemblyInfo>'s public channel
- And whenever a navigation page is added, you can get info on using CollectionChanged event on Resource<IRouteHandler>'s Catalog

Using these info points you can gather lots of info on what is going on.. I donno if it will help you, but they are there.
Rishi

May 26, 2010 at 9:04 PM

Hi Rishi,

I'm just trying to load the SideMap programmatically from the database.  Do you have any sample of programmatically adding NavigationNodes ?

Marcos

Coordinator
May 26, 2010 at 9:28 PM

Hi Marcos, unfortunately I've not got a proper sample that gets the site-map directly from a database - but I don't think it should be that hard. SiteMaps are designed to loaded asynchronously, and you can easily write a provider that uses something like WCF RIA Services or oData to get the mappings.

One other possible solution is to have your DB emit xml for a SiteMap - and built into nRoute is a XmlSiteMapProvider which you can consume that Xml. The Xml schema used by XmlSiteMapProvider is that of WCF's DataContractSerializer which I understand/guess would be compatible with the desktop version. Below is a sample of the Xml that can be used:

<SiteMap xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/nRoute.SiteMaps">
  <Areas>
    <SiteArea>
      <Dependencies>
        <AreaInfo>
          <Key>Sales</Key>
        </AreaInfo>
      </Dependencies>
      <InitializeOnLoad>true</InitializeOnLoad>
      <Key>Accounts</Key>
      <RemoteUrl>nRoute.Samples.Areas.Accounts.xap</RemoteUrl>
    </SiteArea>
    <SiteArea>
      <Dependencies />
      <InitializeOnLoad>true</InitializeOnLoad>
      <Key>Sales</Key>
      <RemoteUrl>nRoute.Samples.Areas.Sales.xap</RemoteUrl>
    </SiteArea>
    <SiteArea>
      <Dependencies />
      <Key>Production</Key>
      <RemoteUrl>nRoute.Samples.Areas.Production.dll</RemoteUrl>
    </SiteArea>
  </Areas>
  <RootNode>
    <ChildNodes>
      <Node i:type="NavigateNode">
        <ChildNodes />
        <IsEnabled>true</IsEnabled>
        <IsListed>true</IsListed>
        <Key>AccountsOverviewPage</Key>
        <SiteArea>Accounts</SiteArea>
        <Title>Accounts Overview</Title>
        <Url>Accounts/Overview/</Url>
        <UrlParameters  />
      </Node>
      <Node i:type="NavigateNode">
        <ChildNodes />
        <IsEnabled>true</IsEnabled>
        <IsListed>true</IsListed>
        <SiteArea>Sales</SiteArea>
        <Title>Sales Overview</Title>
        <Url>Sales/Overview/</Url>
        <UrlParameters />
      </Node>
      <Node i:type="NavigateNode">
        <ChildNodes />
        <IsEnabled>true</IsEnabled>
        <IsListed>true</IsListed>
        <SiteArea>Production</SiteArea>
        <Title>Production Overview</Title>
        <Url>Production/Overview/</Url>
        <UrlParameters />
      </Node>
      <Node i:type="ControllerActionNode">
        <ChildNodes />
        <IsEnabled>true</IsEnabled>
        <IsListed>true</IsListed>
        <Key>HomeAction</Key>
        <SiteArea>Accounts</SiteArea>
        <Title>Home</Title>
        <Url>Taks/Accounts/Home/</Url>
        <UrlParameters />
      </Node>
      <Node i:type="ControllerActionNode">
        <ChildNodes />
        <IsEnabled>true</IsEnabled>
        <IsListed>true</IsListed>
        <Title>Exit</Title>
        <Url>Tasks/Shell/Exit/</Url>
        <UrlParameters />
      </Node>
      <Node i:type="NavigateNode">
        <ChildNodes />
        <IsEnabled>true</IsEnabled>
        <IsListed>true</IsListed>
        <Title>Error Page 1</Title>
        <Url>Page/DoesNotExist1/</Url>
        <UrlParameters />
      </Node>
      <Node i:type="NavigateNode">
        <ChildNodes />
        <IsEnabled>true</IsEnabled>
        <IsListed>true</IsListed>
        <Title>Error Page 2</Title>
        <Url>Page/DoesNotExist2/</Url>
        <UrlParameters />
      </Node>
    </ChildNodes>
    <IsEnabled>true</IsEnabled>
    <IsListed>true</IsListed>
    <Url i:nil="true" />
    <UrlParameters />
  </RootNode>
</SiteMap>

To use a XmlSiteMapProvider is quite simple:

<n:nRouteApplicationService>
	<n:nRouteApplicationService.SiteMapProvider>
		<n:XmlSiteMapProvider XmlFileUrl="SiteMap.xml" />
	</n:nRouteApplicationService.SiteMapProvider>	
</n:nRouteApplicationService>

The SiteMap.xml could be coming either from a static file or be dynamically generated by your Db.
Rishi 

PS: As a tip you could always serialize a Xaml SiteMap declaration to get the Xml version.

May 27, 2010 at 7:19 AM
I initially declared the XamlSiteMapProvider inline as per your example. As for ApplicationLifeTimeObjects vs Resources my understanding was that like any xaml file app.xaml is parsed top-down meaning as long as resources are declared first they should be available for us the app lifetime objects.

As for System.Observable, I do have a reference. I'm using Rx in other parts of the app. If I comment out the declarationof the XamlSiteMapProvider everything compiles though I do get warnings about nRoute.Framework having a dependency on v1.0.0.25 or something of System.Observable.


Sent from my iPhone

On 26 May 2010, at 21:20, "Orktane" <notifications@codeplex.com> wrote:

From: Orktane

Well, from your xaml I can see one problem - you've declared the XamlSiteMapProvider as a static-resource, however as I understand in Silverlight ApplicationLifetimeObjects are initialized much before static resources are availed. So I'd suggest place the XamlProvider declaration directly with the nRouteApplicationService:

<Application.ApplicationLifetimeObjects>
        
    <!-- BOOTSTRAPER -->
    <n:nRouteApplicationService>

        <!-- PROVIDER -->
        <n:XamlSiteMapProvider>
            <n:XamlSiteMapProvider.SiteMap>

                <!-- SITE MAP -->
                <n:SiteMap>
                        
                    <!-- AREAS -->
                    <n:SiteMap.Areas>
                        <n:SiteArea Key="Module" InitializeOnLoad="False" RemoteUrl="nRoute.Samples.SiteMapModule.xap"/>                            
                    </n:SiteMap.Areas>
                        
                    <!-- MAP -->
                    <n:SiteMap.RootNode>
                        <n:NavigationNode Title="Home" Url="Home">

                            <n:NavigationNode Title="Help">
                                <n:NavigationNode Title="About" Url="Help/About" />
                            </n:NavigationNode>

                            <n:NavigationNode Title="Module Content">
                                <n:NavigationNode Key="ModulePageNode" Title="Module Page" Url="Module/Page" SiteArea="Module"/>
                            </n:NavigationNode>

                        </n:NavigationNode>
                    </n:SiteMap.RootNode>
                        
                </n:SiteMap>

            </n:XamlSiteMapProvider.SiteMap>                
        </n:XamlSiteMapProvider>

    </n:nRouteApplicationService>
        
</Application.ApplicationLifetimeObjects>

Secondly, double check you have references to both System.Observable.dll [from Rx Framework] and System.Windows.Interactivity.dll [Version 4.0.5.0]. And as a guess, also ensure your are indeed using Silverlight's nRoute assembly and not WPF or WP7, plus if you are really using those angle-brackets in your SiteMap declarations just try changing them.

Also, I've spiked a small SiteMap's sample (its SiteMap is shown above) which you can download from here:

http://cid-587cbdf035b4a11d.skydrive.live.com/self.aspx/.Public/nRoute.Samples.SiteMapExample.zip

It's working on my machine, it should work with yours too. Let me if you can get things working.

Cheers,
Rishi

May 27, 2010 at 8:04 AM

I just tried the sample on a fresh machine and got the same error as before: XamlSiteMapProvider does not exist in XML namespace http://nRoute/schemas/2010/xaml. I should reiterate that I'm using the latest version of System.Observable: v1.0.2.5. The really weird thing is that it only complains about XamlSiteMapProvider.

I comment out that line and everything builds fine. It doesn't complain about nRouteApplicationService. Also at design time it claims XamlSiteMapProvider is not a SiteMapProvider or something. Weird.

 

Coordinator
May 27, 2010 at 8:17 AM

Strange, but confirm that you are using Silverlight 4 in all your projects, and not by any chance Silverlight 3 as custom xml namespaces aren't allowed in Silverlight 3. Also, if that is not the case, then I suspect there might be some problem with one or more of your references, remove nRoute.Framework, System.Observable and System.Windows.Interactive in all your projects, then clean your solution, and then add them back again. Also make sure you delete both the "Obj" and "Bin" folders in all your projects.

BTW, did the project I uploaded work on either of your machines?
Rishi

May 27, 2010 at 8:40 AM
Edited May 27, 2010 at 8:51 AM

I am using Silverlight 4 in all projects and I've tried cleaning and rebuilding the solution - no joy. I ran the sample you uploaded on a different machine - same error. As for custom xml namespace - even using clr namespace it doesn't work; you get the same error.

What version of System.Observable did you use when you ran the spike?

May 27, 2010 at 8:53 AM

Have you considered making SiteMapProvider on nRouteApplicationService a dependency property?

Coordinator
May 27, 2010 at 9:07 AM

Well, now the only problem I can think of is that maybe you are using an earlier release of either Blend RC [I've got 4.0.20421.0] or Silverlight Tools [I've got RTM version]. SiteMaps are working for me and lots of other projects I know off - the only issue we've had was the design time experience for SiteMaps (see comments at http://www.orktane.com/Blog/post/2010/05/19/nRoute-Samples-Revisited.aspx) but other than that it works fine.

Rishi

Coordinator
May 27, 2010 at 9:09 AM

You are right, SiteMapProvider property on nRouteApplicationService can/should be a DP - and I'll change it in the next release.
Rishi

May 27, 2010 at 9:13 AM

I'm using Blend 4 RC (v4.0.20421.0) and Silverlight Tools RTM

Coordinator
May 27, 2010 at 9:29 AM

Alright here'sone more idea - get the latest source for nRoute, remove the all nRoute.Framework.dll references from all your project, from the source attach the nRoute.Framework.Silverlight.csproj project to your solution, and then add reference to the nRoute project in all your other projects.

Also, like before delete both the "Obj" and "Bin" folders in all your projects. Now, you might be able to pin-point where exactly the problem is by stepping in the code. If you get any particular exception share it with me.

May 27, 2010 at 10:20 AM

By comparing the project files for the Office2010 v2 sample (which works by the way) and one of my projects I found that the former had <ValidateXaml>false</ValidateXaml>. Setting mine to false as well allowed it to build. Obviously this is not I deal though - I'd prefer compile-time checking of my Xaml.

The OfficeXcel sample doesn't work since that has ValidateXaml as true.

May 27, 2010 at 10:29 AM

I rebuilt the source with System.Observable v1.0.2.5 (and made SiteMapProvider on nRouteApplicationService a dependency property). I rebuilt my project using that and this time it compiled (even with ValidateXaml set to true).

Coordinator
May 27, 2010 at 10:36 AM

Ahh I remember I had set to false, but it was coz of some Blend related error - it had nothing to do with SiteMaps. However this is crazy as the uploaded sample worked just fine on my machine without having to set the validate xaml property to false. I reckon this is a tooling problem. Anyway, at least you got it to compile :)

Rishi

Coordinator
May 27, 2010 at 10:44 AM

Excellent.. Seems like you din't have the dlls I updated on the 19th.. I changed the project to be NOT bound to any specific versions of System.Observable.dll and System.Windows.Interactivity.dll

Anyway, happy nRouting :)

May 27, 2010 at 8:48 PM
Would that be the BridgeViewModel behavior that was causing ur problems in blend? It doesn't seem to check if it's in a designer and kept blowing up saying the nRouteApplicationService hadn't been initialized.

Sent from my iPhone

On 27 May 2010, at 11:36, "Orktane" <notifications@codeplex.com> wrote:

From: Orktane

Ahh I remember I had set to false, but it was coz of some Blend related error - it had nothing to do with SiteMaps. However this is crazy as the uploaded sample worked just fine on my machine without having to set the validate xaml property to false. I reckon this is a tooling problem. Anyway, at least you got it to compile :)

Rishi

Coordinator
May 27, 2010 at 9:47 PM
@jimitndiaye I'm not sure if BridgeViewModel was the culprit, but generally BridgeViewModel hasn't given me any problems as far as Blend is concerned. Though just remember that BridgeViewModel behavior much be attached to a "view" instance which has a corresponding ViewModel defined. Rishi
May 28, 2010 at 8:56 AM

On a related note Rishi, a lot of your latest samples have unnecessary references to System.Observable (that can be removed since its in .NET 4) as well as small other issues that need fixing before the samples compile.  For example the WebExcel project has references to an absolute hardcoded path, etc.  I cant remember the other specific problems and they are very simple to fix but just thought id let you know

Coordinator
May 28, 2010 at 10:31 AM

@Xcalibur in all Silverlight and WP7 apps reference to System.Observable.dll is required, for WPF with .NET v3.5 you require System.Observable but with .NET v4 you don't need it. So basically, the only exception to requiring System.Observable is WPF with .NET 4. As for some samples wrongly tied up, well my bad - I'll try to be more careful going forward.

Rishi

May 31, 2010 at 5:09 AM

Its ok i know you are primarily a Silverlight dev so we cant expect too much :oP  Going forward Im happy to validate any WPF stuff if it would be helpful or save you some time.

cheers