XamlSiteMapProvider strange error

Feb 17, 2011 at 10:17 AM

Hi,

I'm using the newest nRoute version and there is a strange issue. I've tested the solution on 5 computers. On three of them it works with no problem. But on two there is an error saying that XamlSiteMapProvider could not be found :/

Here part of the code of App.xaml:

<Application.ApplicationLifetimeObjects>
        <n:nRouteApplicationService>
            <n:nRouteApplicationService.SiteMapProvider>
                <n:XamlSiteMapProvider>
                    <n:SiteMap>
                        
                        <!-- ROOT NODE -->
                        <n:SiteMap.RootNode>
                            <n:NavigationNode>
                                <n:NavigationNode Title="home" Url="Content/Pages/Home/" />
                                <n:NavigationNode Title="Promocje" Url="Content/Pages/Promocje/" />
                            </n:NavigationNode>
                        </n:SiteMap.RootNode>
                        
                    </n:SiteMap>
                </n:XamlSiteMapProvider>
            </n:nRouteApplicationService.SiteMapProvider>
        </n:nRouteApplicationService>
    </Application.ApplicationLifetimeObjects>

 

I've checked the DLL version on the computers not working. Everything has the same version/build. The project is in SL 4 build in VS2010.

Any suggestions what maybe causing the problem?


Coordinator
Feb 17, 2011 at 10:31 AM
Edited Feb 17, 2011 at 10:34 AM

By newest you mean v0.5? If so then you'll need to create child NodesCollection yourself, i.e.:

 

<!-- ROOT NODE -->
<n:SiteMap.RootNode>
	<n:NavigationNode>
		<n:NodesCollection>
			<n:NavigationNode Title="home" Url="Content/Pages/Home/" />
			<n:NavigationNode Title="Promocje" Url="Content/Pages/Promocje/" />
		</n:NodesCollection>
	</n:NavigationNode>
</n:SiteMap.RootNode>

 

I removed the auto-creation of child nodes collection to allow for more efficient serialization/deserialization. I might put it back, but for now just pls create the collection container.

Cheers,
Rishi

Feb 17, 2011 at 10:34 AM

Sorry, by newwest I meant the stable version which is: 0.4.5

Coordinator
Feb 17, 2011 at 10:50 AM

Then that is a designer error - which rears its head somewhat randomly. I'm looking into correcting it in v0.5, but for now you can safely ignore it as it won't stop you from building your project.

Cheers,
Rishi 

Feb 17, 2011 at 10:51 AM

But it's not an design time error but run time error. When I launch the app on 5 different computers on 3 of them it works but on 2 it doesn't with the same error :/

Coordinator
Feb 17, 2011 at 11:37 AM

That's crazy then - can you confirm the Silverlight runtime versions where it is working and where it is not?
Rishi

Feb 17, 2011 at 11:48 AM

It is working on different SL runtime versions and it's not working on the same runtime on which it is working on another computer :/

Coordinator
Feb 17, 2011 at 12:13 PM

You'll then need to provide a small repo with more info, because this is too abstract/random - elsewhere I'm using xamlsitemaprovider in apps that are used in 1000's of computers without problem.

Also, the problem could be something that the sitemap or sitemap node is trying to do and is failing, and that is being masked in a generic error - just try removing/adding nodes in a piece by piece manner.

Rishi

Feb 21, 2011 at 10:51 AM

I've tried removing the nodes one by one but with effects :(

I've removed the whole sitemapprovider from App.xaml and now I get an error:

{nRoute.Components.Composition.ResolveResourceException: Cannot resolve a default constructor to use for OmniPharmSL.ViewModels.Grupy.EdycjaGrupyViewModel, please specify using ResolveConstructor Attribute
   w nRoute.Components.Composition.TypeDescriptor.ActivatorConstructorDescriptor()
   w nRoute.Components.Composition.TypeDescriptor..ctor(Type type)
   w nRoute.Components.Composition.TypeBuilder.CreateDescriptorBuilder(Type type)
   w nRoute.Components.Composition.TypeBuilder.BuildType(Type type, Boolean useReflection)
   w nRoute.Components.Composition.TypeBuilder.BuildType(Type type)
   w nRoute.ViewModels.ViewModelProvider.CreateViewModelInstance()
   w nRoute.Behaviors.BridgeViewModelBehavior.OnAttached()
   w System.Windows.Interactivity.Behavior.Attach(DependencyObject dependencyObject)
   w System.Windows.Interactivity.BehaviorCollection.ItemAdded(Behavior item)
   w System.Windows.Interactivity.AttachableCollection`1.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   w System.Windows.DependencyObjectCollection`1.TryCollectionChanged(NotifyCollectionChangedEventArgs e)
   w System.Windows.DependencyObjectCollection`1.System.Collections.IList.Add(Object value)
   w MS.Internal.XamlManagedRuntimeRPInvokes.Add(XamlQualifiedObject& qoCollection, XamlPropertyToken inCollectionProperty, XamlQualifiedObject& inValue)}
Coordinator
Feb 21, 2011 at 10:56 AM

Right that's a simple error - on EdycjaGrupyViewModel type nRoute can't choose which constructor to use so just adorn one of the constructor with a [ResolveConstructor] attribute and it should work.

Rishi

Feb 21, 2011 at 11:07 AM

Sorry, my bad ;) the correct error I get should be:

{System.Windows.Markup.XamlParseException: Add value to collection of type 'System.Windows.Interactivity.BehaviorCollection' threw an exception. [Line: 13 Position: 30] ---> System.InvalidOperationException: nRouteApplicationService has not been initialized.
   w nRoute.Behaviors.BridgeViewModelBehavior.OnAttached()
   w System.Windows.Interactivity.Behavior.Attach(DependencyObject dependencyObject)
   w System.Windows.Interactivity.BehaviorCollection.ItemAdded(Behavior item)
   w System.Windows.Interactivity.AttachableCollection`1.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   w System.Windows.DependencyObjectCollection`1.TryCollectionChanged(NotifyCollectionChangedEventArgs e)
   w System.Windows.DependencyObjectCollection`1.System.Collections.IList.Add(Object value)
   w MS.Internal.XamlManagedRuntimeRPInvokes.Add(XamlQualifiedObject& qoCollection, XamlPropertyToken inCollectionProperty, XamlQualifiedObject& inValue)
   --- Koniec śladu stosu wyjątków wewnętrznych ---
   w System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   w SL.GUI.MainPage.InitializeComponent()
   w SL.GUI.MainPage..ctor()}
Coordinator
Feb 21, 2011 at 11:36 AM

That tells me either you are missing a nRouteApplicationService declaration in your app.xaml or during the initialization (of nRouteApplicationService) there was some error. So either add nRouteApplicationService to your app.xaml (see http://nroute.codeplex.com/wikipage?title=Bootstrapping) or if you already have it, then look for an inner-exception to see what was the real cause for the error. You can also step-in the initialization to see if there is something failing.

Cheers,
Rishi 

Feb 21, 2011 at 12:00 PM

Unfortunately that's all :( the inner exception is just repiting the message I've posted... really have no idea what can be the issue...

Coordinator
Feb 21, 2011 at 12:13 PM
Then check the inner-inner exception – or send me a repo, and I can have a look. I’m pretty sure it’s something small that is tripping your code.
Rishi
Feb 21, 2011 at 12:47 PM

Here is the InnerEception:

{System.InvalidOperationException: nRouteApplicationService has not been initialized.
   w nRoute.Behaviors.BridgeViewModelBehavior.OnAttached()
   w System.Windows.Interactivity.Behavior.Attach(DependencyObject dependencyObject)
   w System.Windows.Interactivity.BehaviorCollection.ItemAdded(Behavior item)
   w System.Windows.Interactivity.AttachableCollection`1.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   w System.Windows.DependencyObjectCollection`1.TryCollectionChanged(NotifyCollectionChangedEventArgs e)
   w System.Windows.DependencyObjectCollection`1.System.Collections.IList.Add(Object value)
   w MS.Internal.XamlManagedRuntimeRPInvokes.Add(XamlQualifiedObject& qoCollection, XamlPropertyToken inCollectionProperty, XamlQualifiedObject& inValue)}

And the Stack Trace:

w System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   w SL.GUI.MainPage.InitializeComponent()
   w SL.GUI.MainPage..ctor()

The problem is that repo is kind of hard. The issue looked like this. My two co-developers were working on some other stuff and in the meanwhile I've created od TFS a solution which works perfect on my computer in VS, and three other computers. But on theirs it doesn't.

The funny thing is that one of the devs has some earlier nRoroute app I've made and it works on his computer.

Feb 24, 2011 at 10:28 AM
Edited Feb 24, 2011 at 10:28 AM

Ok, problem solved :)

On the computers in which the app didn't work we've uninstalled: SL Tools for VS 2010, SL Toolkit, SL 4 SDK, Rx, WCF Ria Services, Blend SDK and reinstalled them in this order: SL Tools for VS 2010 -> SL Toolkit -> Rx All Platforms -> Blend SDK

and all is good :)

Coordinator
Feb 24, 2011 at 10:04 PM

Humm.. strange, but thanks for this handy tip.
Rishi 

May 16, 2011 at 9:31 AM

Had the same problem but was due to some "could not find" System.Observable.dll.  

You should look for exceptions in your output window.

I think nRoute does some dynamic assembly loading, and if it fails to find an assembly then nRouteApplicationService remains un-initialized but you get no explicit exception thrown describing the problem.