Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

Setting WPF Frame source to a XAML file in an external dll referenced as a NuGet Package causes exception

$
0
0

As part of the navigation mechanism in my WPF MVVM application I am trying to set the Source property of a Frame control to my View (a UserControl) located in an external assembly (dll file) referenced via a private NuGet Package.

This is the package reference in my csproj file:

<PackageReference Include="MyCompany.UI.Views" Version="1.0.0" />

and this is how I set the Frame source:

navFrame.Source = new Uri("/MyCompany.UI.Views;component/MyView.xaml", UriKind.RelativeOrAbsolute);

//or this (both are basically the same):

navFrame.Source = new Uri("pack://application:,,,/MyCompany.UI.Views;component/MyView.xaml", UriKind.RelativeOrAbsolute);

The problem is that as soon as I set the Source of the Frame I get a System.Windows.Markup.XamlParseException with the following message:

Could not register named object. Cannot register duplicate name 'MyGrid' in this scope.

MyGrid being the first named control in my UserControl.

Well, obviously I don't have any duplicate names in my UserControl and all my other internal Views are OK when set as the source of the Frame. This makes the existence of the view in an external assembly my only suspect for causing this exception. I have tried different ways of formatting the Uri path but none have helped.

Any clues what might be cause of this problem?

P.S. I should point out that previously when we didn't place the UI project (including the View) in a NuGetPackage, and referenced it as a project directly to the main application project, we faced no exceptions.


Viewing all articles
Browse latest Browse all 3067

Trending Articles